Skip to content

Instantly share code, notes, and snippets.

@maliming
Created November 21, 2020 13:01
Show Gist options
  • Save maliming/a28a4033613cfe1139f0b7bf21366784 to your computer and use it in GitHub Desktop.
Save maliming/a28a4033613cfe1139f0b7bf21366784 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo
{
[Area("Test")]
[Route("Test/[action]")]
public class TestController : AbpController, IRemoteService
{
[HttpGet]
public IActionResult GetMethod1([FromQuery(Name = "n.a.m.e")] string name)
{
return new JsonResult($"{name}");
}
[HttpGet]
public IActionResult GetMethod2(TestMethod2Model input)
{
return new JsonResult($"{input.Name}, {input.Age}");
}
[HttpGet]
public IActionResult GetMethod3(TestMethod3Model input)
{
return new JsonResult($"{input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpGet]
[Route("by/{id}/{name}")]
public IActionResult GetMethod4(Guid id,string name, TestMethod3Model input)
{
return new JsonResult($"{name}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpGet]
public IActionResult GetMethod5([FromHeader(Name = "v.s")]string version ,TestMethod3Model input)
{
return new JsonResult($"{version}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpGet]
[Route("by/{name}")]
public IActionResult GetMethod6([FromRoute(Name = "name")]string myName, [FromHeader(Name = "v.s")]string version ,TestMethod3Model input)
{
return new JsonResult($"{myName}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpGet]
[Route("with/{name}")]
public IActionResult GetMethod7([FromRoute(Name = "name")]string myName, [FromHeader(Name = "v.s")]string version, [FromBody]TestMethod3Model input)
{
return new JsonResult($"{myName}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpPost]
public IActionResult PostMethod1([FromForm(Name = "n.a.m.e")] string name)
{
return new JsonResult($"{name}");
}
[HttpPost]
public IActionResult PostMethod2([FromForm]TestMethod2Model input)
{
return new JsonResult($"{input.Name}, {input.Age}");
}
[HttpPost]
public IActionResult PostMethod3([FromForm]TestMethod3Model input)
{
return new JsonResult($"{input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpPost]
[Route("by/{id}/{name}")]
public IActionResult PostMethod4(Guid id,string name, [FromForm]TestMethod3Model input)
{
return new JsonResult($"{name}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpPost]
public IActionResult PostMethod5([FromHeader(Name = "v.s")]string version, [FromForm]TestMethod3Model input)
{
return new JsonResult($"{version}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpPost]
[Route("by/{name}")]
public IActionResult PostMethod6([FromRoute(Name = "name")]string myName, [FromHeader(Name = "v.s")]string version, [FromForm]TestMethod3Model input)
{
return new JsonResult($"{myName}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
[HttpPost]
[Route("with/{name}")]
public IActionResult PostMethod7([FromRoute(Name = "name")]string myName, [FromHeader(Name = "v.s")]string version, [FromBody]TestMethod3Model input)
{
return new JsonResult($"{myName}, {input.Name}, {input.Age}, {input.InnerModel?.Name}, {input.InnerModel?.Age}");
}
}
public class TestMethod2Model
{
[BindProperty(Name = "My.Name")]
public string Name { get; set; }
[BindProperty(Name = "My_Age")]
public int Age { get; set; }
}
public class TestMethod3Model
{
[BindProperty(Name = "My.Name")]
public string Name { get; set; }
[BindProperty(Name = "My_Age")]
public int Age { get; set; }
[BindProperty(Name = "My.Inner")]
public TestMethod2InnerModel InnerModel { get; set; }
}
public class TestMethod2InnerModel
{
[BindProperty(Name = "Inner.Na.me")]
public string Name { get; set; }
public int Age { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment