public IHttpActionResult UpdateContactDetails(string name, [FromBody] ContactDetailDTO updatedDetails) { try { if (updatedDetails == null) { ModelState.AddModelError("Contact Detail", "contact Detail cannot be null"); return(BadRequest(ModelState)); } if (String.IsNullOrWhiteSpace(name)) { ModelState.AddModelError("Name", "Name to be updated cannot be null"); } ContactDetailValidator ContactDetailvalidator = new ContactDetailValidator(); ValidationResult result = ContactDetailvalidator.Validate(updatedDetails); if (!result.IsValid || !ModelState.IsValid) { foreach (var failure in result.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); } return(BadRequest(ModelState)); } Mapper.CreateMap <ContactDetailDTO, ContactDetail>(); ContactDetail contactDetail = Mapper.Map <ContactDetail>(updatedDetails); bool detailAdded = _contactDetailsBl.UpdateContactDetail(name, contactDetail); if (detailAdded) { return(Ok("Contact Detail Updated Successfully")); } else { return(Ok("Contact Detail cannot be Updated")); } } catch (Exception) { return(InternalServerError()); } }
public IHttpActionResult AddContactDetails([FromBody] ContactDetailDTO contactDto) { try { if (contactDto == null) { ModelState.AddModelError("Contact Detail", "contact Detail cannot be null"); return(BadRequest(ModelState)); } ContactDetailValidator ContactDetailvalidator = new ContactDetailValidator(); ValidationResult result = ContactDetailvalidator.Validate(contactDto); if (!result.IsValid) { foreach (var failure in result.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); } return(BadRequest(ModelState)); } Mapper.CreateMap <ContactDetailDTO, ContactDetail>(); ContactDetail contactDetail = Mapper.Map <ContactDetail>(contactDto); bool detailAdded = _contactDetailsBl.AddContactDetail(contactDetail); if (detailAdded) { return(Ok("Contact Detail Added Successfully")); } else { return(Ok("Contact Detail cannot be added")); } } catch (Exception) { return(InternalServerError()); } }