public async Task <IActionResult> PutContact(long id, Contact contact) { contactValidator validator = new contactValidator(); var errorList = validator.ValidateContact(contact); if (errorList.Any()) { return(new BadRequestObjectResult(errorList)); } contact.Id = id; await _service.UpdateContactAsync(contact); return(new NoContentResult()); }
public async Task <ActionResult <Contact> > PostContact(Contact contact) { contactValidator validator = new contactValidator(); var errorList = validator.ValidateContact(contact); if (errorList.Any()) { return(new BadRequestObjectResult(errorList)); } var existingContact = await _service.SearchAsync(contact.Email); if (existingContact == null) { await _service.SaveContactAsync(contact); return(CreatedAtAction(nameof(GetContact), new { id = contact.Id }, contact)); } else { return(new BadRequestObjectResult($"The email {contact.Email} it´s already in use")); } }