Skip to content

Instantly share code, notes, and snippets.

@squadwuschel
Created October 22, 2016 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squadwuschel/872caf3b58ef81b942f9e33968ee2a78 to your computer and use it in GitHub Desktop.
Save squadwuschel/872caf3b58ef81b942f9e33968ee2a78 to your computer and use it in GitHub Desktop.
.NET Controller für Angular 2 Proxygenerierung
using ProxyGenerator.ProxyTypeAttributes;
public class ProxyController : Controller
{
[CreateAngular2TsProxy(ReturnType = typeof(Person))]
public JsonResult AddTsEntryOnly(Person person)
{
return Json(person, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Auto))]
public JsonResult AddTsEntryAndName(Person person, string name)
{
return Json(new Auto() { Marke = name }, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Person))]
public JsonResult LoadTsCallById(int id)
{
return Json(new Person() { Id = id }, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Person))]
public JsonResult LoadTsCallByParams(string name, string vorname, int alter)
{
return Json(new Person() { Name = name, Id = alter }, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Auto))]
public JsonResult LoadTsCallByParamsWithEnum(string name, string vorname, int alter, ClientAccess access)
{
return Json(new Auto() { Marke = name, Alter = alter }, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(List<Auto>))]
public JsonResult LoadAllAutosListe(string name)
{
return Json(new List<Auto>() { new Auto() { Marke = name }, new Auto() }, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Person))]
public JsonResult ClearTsCall()
{
return Json(new Person(), JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(void))]
public JsonResult VoidTsReturnType(string name)
{
return Json(string.Empty, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(string))]
public JsonResult StringTsReturnType(string name)
{
return Json(name, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(int))]
public JsonResult IntegerTsReturnType(int age)
{
return Json(age, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(DateTime))]
public JsonResult DateTsReturnType(string name)
{
return Json(DateTime.Now, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(ReturnType = typeof(Boolean))]
public JsonResult BoolTsReturnType(bool boolValue)
{
return Json(boolValue, JsonRequestBehavior.AllowGet);
}
[CreateAngular2TsProxy(CreateWindowLocationHrefLink = true)]
public FileResult GetDownloadSimple(int companyId, string name)
{
var fileContent = Encoding.ASCII.GetBytes(string.Format("Das ist ein Test Download für die CompanyId: {0} mit dem Namen: {1}", companyId, name));
return File(fileContent, "text/text", "TestDL.txt");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment