public IActionResult Create() { var data = new CreateViewModel { Users = GetUsersListItems() }; return View(data); }
public async Task<IActionResult> Create(CreateViewModel model) { try { if (ModelState.IsValid) { var contact = new Contact { ContactId = Guid.Empty, FirstName = model.FirstName, LastName = model.LastName, Company = model.Company, Title = model.Title, Trade = model.Trade, Phone = model.Phone, Email = model.Email, Chat = model.Chat, Website = model.Website, UserId = model.UserId }; context.Contacts.Add(contact); await context.SaveChangesAsync(); return RedirectToAction(nameof(ContactsController.Details), new { id = contact.ContactId }); } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return View(model); }