public async Task <ContactServiceModel> CreateAsync(ContactServiceModel serviceModel) { Contact contact = serviceModel.To <Contact>(); await this.context.Contacts.AddAsync(contact); await this.context.SaveChangesAsync(); return(contact.To <ContactServiceModel>()); }
//Create contact public ActionResult Post(ContactViewModel contact) { contactsService = new ContactsService(); cmAPI = new ContactManagerAPIController(contactsService); Mapper.CreateMap <ContactViewModel, ContactServiceModel>(); ContactServiceModel csvcVM = Mapper.Map <ContactViewModel, ContactServiceModel>(contact); var addedContact = cmAPI.Post(csvcVM); return(RedirectToAction("Get")); }
//Update contact public ActionResult Put([FromBody] ContactViewModel updatedContactVM) { contactsService = new ContactsService(); cmAPI = new ContactManagerAPIController(contactsService); // Check if contact exists to update. Mapper.CreateMap <ContactViewModel, ContactServiceModel>(); ContactServiceModel csvcVM = Mapper.Map <ContactViewModel, ContactServiceModel>(updatedContactVM); cmAPI.Put(csvcVM); return(RedirectToAction("Get")); }