public ActionResult Index(RegistrantViewModel model) { if (ModelState.IsValid) { var registrant = new Registrant(); var names = ParseFullName(model.FullName); if (names.Length > 2) { registrant.LastName = names[0]; registrant.MiddleName = names[1]; registrant.FirstName = names[2]; } else if (names.Length > 1) { registrant.LastName = names[0]; registrant.FirstName = names[1]; } else { ViewBag.Gender = _genderListProducer.BuildList(); ModelState.AddModelError("", "At the very minimum, a first name and a surname are required"); return(View()); } if (_registrantPersistenceService.GetUnique(model.EmailAddress, model.PhoneNumber) != null) { ViewBag.Gender = _genderListProducer.BuildList(); ModelState.AddModelError("", "Seems like you have already registered. We already have that phone number and or Email address"); return(View(model)); } registrant.Email = model.EmailAddress; registrant.PhoneNumber = model.PhoneNumber; registrant.Gender = model.Gender; registrant.State = model.State; registrant.Institution = model.Institution; _registrantPersistenceService.Insert(registrant); TempData["Message"] = "Thanks for indicating interest!"; return(RedirectToAction("Index")); } ViewBag.Gender = _genderListProducer.BuildList(); return(View(model)); }
//Post registrants to DB public IHttpActionResult Post(RegistrantViewModel registrant) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (empire_dbContext dbContext = new empire_dbContext()) { dbContext.tblRegistrants.Add(new tblRegistrant() { fname = registrant.Fname, lname = registrant.Lname }); dbContext.SaveChanges(); } return(Ok()); }
public ActionResult Index(RegistrantViewModel registrant) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://hartempire.azurewebsites.net/api/registration"); //HTTP POST var postTask = client.PostAsJsonAsync <RegistrantViewModel>("registration", registrant); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(registrant)); }