public IHttpActionResult create(stud_Details s) { StudentEntities2 obj = new StudentEntities2(); obj.stud_Details.Add(s); obj.SaveChanges(); return(Ok("successfull")); }
public HttpResponseMessage GetAuthToken(stud_Details s) { BusinessService bs = new BusinessService(); var token = bs.generatetoken(s.UserName, s.Password); var response = Request.CreateResponse(HttpStatusCode.OK, "Authorized"); response.Headers.Add("Token", token.Token); response.Headers.Add("TokenExpiry", DateTime.Now.AddHours(2).ToString()); response.Headers.Add("Access-Control-Expose-Headers", "Token,TokenExpiry"); return(response); }
public stud_Details generatetoken(string name, string password) { string token = Guid.NewGuid().ToString(); DateTime issuedOn = DateTime.Now; DateTime expiredOn = DateTime.Now.AddSeconds(50000000); var tokd = new stud_Details { Expiry = expiredOn, Token = token, UserName = name }; StudentEntities2 obj = new StudentEntities2(); obj.stud_Details.Add(tokd); obj.SaveChanges(); return(tokd); }
public ActionResult Create(stud_Details student) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:60188//api/"); //HTTP POST var postTask = client.PostAsJsonAsync("student", student); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(student)); }
public IHttpActionResult create(stud_Details s) { if (!ModelState.IsValid) { return(BadRequest("Invalid student.")); } using (var context = new StudentEntities()) { context.stud_Details.Add(new stud_Details() { ID = s.ID, Name = s.Name, Age = s.Age }); context.SaveChanges(); return(Ok("successfull")); } }