Created
October 6, 2018 00:15
-
-
Save jinan-kordab/b87ae47fd93a53b5ee28b7de70fbff2f to your computer and use it in GitHub Desktop.
WEB API C# Controller , inside ASP.NET MVC project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HttpResponseMessage Get(string u, string p) | |
{ | |
Uri referrer = HttpContext.Current.Request.UrlReferrer; | |
dynamic myModel = new Models.MyModel(); | |
CirculationMonitor.Controllers.HomeController hc = new HomeController(); | |
string sd = DateTime.Now.ToShortDateString(); | |
string ed = DateTime.Now.ToShortDateString(); | |
var response = new HttpResponseMessage(HttpStatusCode.OK); | |
if (referrer != null) | |
{ | |
hc.FillMysModel(myModel,(Convert.ToInt32(p) / 678957 )); | |
string myviewPath = HttpContext.Current.Server.MapPath(@"~/Views/Home/MyViewToReturn.cshtml"); | |
var template = System.IO.File.ReadAllText(myviewPath); | |
string parsedView = RazorEngine.Razor.Parse(template, myModel); | |
response.Content = new StringContent(parsedView); | |
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"); | |
} | |
else | |
{ | |
response.Content = new StringContent("<html><body><h5>Not authorized. Please use the link on ASP page to getyour product</h5></body></html>"); | |
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"); | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment