public async Task <ActionResult> Student(StudentLogicModel student) { if (!student.ValidatePassword()) { ViewBag.Error = "Password must be at least 6 characters. Password and confirm password must match."; return(View(student)); } using (var client = SetupClientAndSetMenu(2)) { var url = ApiUriHelper.GetBaseUri() + ApiUriHelper.StudentUrl; try { var response = await client.PostAsJsonAsync <StudentLogicModel>(url, student); if (response.IsSuccessStatusCode) { return(RedirectToAction("Students")); } else { ViewBag.Error = "Can't create student account"; return(View(student)); } } catch (Exception ex) { ViewBag.Error = "Error: " + ex.Message; return(View(student)); } } }
public IHttpActionResult AddStudent([FromBody] StudentLogicModel student) { var entity = student.ToEntity(); Logic.AddStudent(entity); return(JsonEx(entity.Id)); }