public IActionResult CreateContact([FromBody] ContactCreationDto newContact) { if (newContact == null) { return(BadRequest()); } //ModelState.AddModelError("Description", "The provided description should be different from the name."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //TODO Implement unique email namd combination //map properties to entity framwork to pass to save method of contact repo var finalContact = Mapper.Map <Contact>(newContact); //call saving method _contactRepository.AddContact(finalContact); //verify that data layer persisted new contact if (!_contactRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } var contactForDataTransmission = Mapper.Map <Models.ContactsDto>(finalContact); return(CreatedAtRoute("GetContact", new { id = contactForDataTransmission.Id }, contactForDataTransmission)); }
public void CreateIfNeededAndAddToSplit() { var contactController = CreateController(); var contactCreationDto = new ContactCreationDto { Email = "*****@*****.**", Name = "John Smith" }; var contactDto = contactController.Controller.CreateIfNeededAndAddToSplit(1, contactCreationDto); Assert.Equal(contactCreationDto.Email, contactDto.Email); Assert.Equal(contactCreationDto.Name, contactDto.Name); }
public ContactDto CreateIfNeededAndAddToSplit([FromRoute] int splitId, [FromBody] ContactCreationDto contactCreationDto) { return(_mapper.Map <ContactDto>(_contactService.CreateIfNeededAndAddToSplit(splitId, contactCreationDto.Email, contactCreationDto.Name))); }