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>());
        }
예제 #2
0
        //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"));
        }
예제 #3
0
        //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"));
        }