public IActionResult CreateResident([FromBody] ResidentCreateDto ResidentDto) { if (ResidentDto == null) { return(BadRequest(ModelState)); } if (_reRepo.ResidentExists(ResidentDto.IdentityNumber)) { ModelState.AddModelError("", "Resident Exists!"); return(StatusCode(404, ModelState)); } var ResidentObj = _mapper.Map <Resident>(ResidentDto); if (!_reRepo.CreateResident(ResidentObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {ResidentObj.IdentityNumber}"); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetResident", new { version = HttpContext.GetRequestedApiVersion().ToString(), ResidentId = ResidentObj.Id }, ResidentObj)); }