public IActionResult CreateContact([FromBody] Contact contact) { if (contact == null) { return(BadRequest()); } Tuple <bool, bool, bool> notUniqueContactFields = new Tuple <bool, bool, bool>(false, false, false); if (String.IsNullOrEmpty(contact.Name) || String.IsNullOrEmpty(contact.Address) || String.IsNullOrEmpty(contact.MobilePhone)) { ModelState.AddModelError("Name/Address/MobilePhone", "Name, Address and MobilePhone shouldn't be empty"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } notUniqueContactFields = _contactsService.CheckUniqueContactFields(contact.ContactId, contact.Name, contact.Address); if (notUniqueContactFields.Item1) { ModelState.AddModelError("ContactId", "ContactId is not unique"); } if (notUniqueContactFields.Item2) { ModelState.AddModelError("Name", "Name is not unique"); } if (notUniqueContactFields.Item3) { ModelState.AddModelError("Address", "Address is not unique"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var createdContact = _contactsService.AddContact(contact); // Live Update for Client Apps _hub.Clients.All.SendAsync("LiveUpdate"); return(Created("contact", createdContact)); } catch (Exception ex) { log.Error("PublicAddressBookApiError: ", ex); return(StatusCode(StatusCodes.Status500InternalServerError)); } }