public ActionResult Post([FromBody] PostContactRequest contactViewModel) { try { if (ModelState.IsValid) { var newContact = new Contact(); newContact.Id = Guid.NewGuid(); newContact.Name = contactViewModel.Name; newContact.Surname = contactViewModel.Surname; newContact.Email = contactViewModel.Email; newContact.Address = contactViewModel.Address; newContact.FixedPhone = contactViewModel.FixedPhone; newContact.MobilePhone = contactViewModel.MobilePhone; _contactsRepository.AddEntity(newContact); if (_contactsRepository.SaveAll()) { return(Created($"api/contacts/{newContact.Id}", newContact)); } } } catch (Exception ex) { return(BadRequest($"Failed to create new contact: {ex}")); } return(BadRequest("Failed to create new contact")); }