public ActionResult Create() { var dropdownlist_Partner_Property = new CreateViewModel.DropDownList_Partner() { Partners = PartnerService.GetPartners().ToList() }; var createViewModel = new CreateViewModel() { DropDownList_Partner_Property = dropdownlist_Partner_Property, IsMale = true }; return View(createViewModel); }
public ActionResult Create(CreateViewModel createViewModel) { if (!ModelState.IsValid) { return View(createViewModel); } var selectedPartner = PartnerService.FindById(createViewModel.DropDownList_Partner_Property.SelectedPartner); var contact = new Contact() { Name = createViewModel.Name, Position = createViewModel.Position, Email = createViewModel.Email, Phone = createViewModel.Phone, Note = createViewModel.Note, IsMale = createViewModel.IsMale, IsBooker = createViewModel.IsBooker, Partner = selectedPartner, }; if (!String.IsNullOrEmpty(createViewModel.Birthday)) { contact.Birthday = DateTime.ParseExact(createViewModel.Birthday, "dd/MM/yyyy", CultureInfo.InvariantCulture); } else { contact.Birthday = null; } if (createViewModel.DropDownList_Partner_Property.SelectedPartner != -1) { contact.PartnerId = createViewModel.DropDownList_Partner_Property.SelectedPartner; } else { contact.PartnerId = null; } ContactService.CreateContact(contact); TempData["ContactId"] = contact.ContactId; TempData["ContactName"] = contact.Name; TempData["Message"] = DocumentsMessage.CreateSuccess; return RedirectToAction("index", "contacts"); }