public ActionResult Create(ContactCreateViewModel contactCreateViewModel) { try { Contact contact = new Contact(); contact.Id = contactCreateViewModel.Id; contact.FirstName = contactCreateViewModel.FirstName; contact.LastName = contactCreateViewModel.LastName; contact.Email = contactCreateViewModel.Email; contact.DateCreated = DateTime.Now; contact.DateUpdated = DateTime.Now; var account = _accountQueries.GetOneById(contactCreateViewModel.AccountOnSelect); contact.Accounts.Add(account); _contactQueries.Save(contact); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.Message = "Contact Creation Failed. Try another Email."; //e.Message; return(View()); } }
public ActionResult Edit(int id) { var account = _accountQueries.GetOneById(id); var contactSelectIds = new List <int>(); foreach (var contact in account.Contacts) { contactSelectIds.Add(contact.Id); } var contacts = _contactQueries.GetAll(); account.Contacts = contacts; var viewModel = _mapperForAccount.MapToAccountEditViewModel(account, contactSelectIds); return(View(viewModel)); }