public ActionResult Create() { var contact = new MyContact(); if (TempData["error"] != "") { ViewBag.Error = TempData["error"]; } return View(contact); }
public ActionResult Create(MyContact contact) { var _contact = new Contact(contact.Name, contact.PhoneNumber, contact.BirthDate); if (!modelPhoneBook.Add(_contact)) { TempData["error"] = "Your POST data entered is incorrect."; return Redirect("Create"); } return RedirectToAction("Index"); }
public string FastCreate(MyContact contact) { var _contact = new Contact(contact.Name, contact.PhoneNumber, contact.BirthDate); var messageData = new MessageData(true); var finalContactKeyValue = modelPhoneBook.AddAndFullReturn(_contact); if (modelPhoneBook.ContactKeyValueIsNull(finalContactKeyValue)) { messageData.Status = false; messageData.Message = "Your data entered is incorrect."; } else messageData.Message = "{\"Name\":\"" + finalContactKeyValue.Value.Name + "\",\"PhoneNumber\":\"" + finalContactKeyValue.Value.PhoneNumber + "\",\"BirthDate\":\"" + finalContactKeyValue.Value.BirthDate + "\",\"Key\":\"" + finalContactKeyValue.Key + "\"}"; return messageData.Message; }