Example #1
0
 public HttpResponseMessage Create(HttpRequestMessage request, ContactDetailViewModel contactDetailViewModel)
 {
     return(CreateHttpResponse(request, ()
                               =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var contactDettail = Mapper.Map <ContactDetailViewModel, ContactDetail>(contactDetailViewModel);
             _contactDetailService.AddContactDetail(contactDettail);
             _contactDetailService.Save();
             response = request.CreateResponse(HttpStatusCode.Created, contactDetailViewModel);
         }
         return response;
     }));
 }
Example #2
0
        public ActionResult AddContactDetail(ContactDetailsViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest("contact detail model is empty"));
                }

                var contact = _mapper.Map <ContactDetails>(model);

                _contactDetailService.AddContactDetail(contact);

                return(Ok("Contact has been loaded successfully"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }