コード例 #1
0
        public ActionResult Create()
        {
            var contact = new MyContact();
            if (TempData["error"] != "")
            {
                ViewBag.Error = TempData["error"];
            }

            return View(contact);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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;
        }