public IActionResult CreateUser([FromBody] UserForCreationDto userDto) { if (userDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var userEntity = Mapper.Map <User>(userDto); _registrationRepository.AddUser(userEntity); if (!_registrationRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdUserToReturn = Mapper.Map <UserWithRolesDto>(userEntity); return(CreatedAtRoute("GetUser", new { subscriberId = createdUserToReturn.SubscriberId }, createdUserToReturn)); } catch (DbUpdateException ex) { if (ex.InnerException is SqlException innerException && innerException.Number == 2601) { return(BadRequest("Subscriber ID already exists - Duplicate Subscriber ID")); }
public IHttpActionResult SaveUser(RegistrationViewDetailsModel objuser) { int result = 0; var user = new Registration() { FirstName = objuser.FirstName, MiddleName = objuser.MiddleName, LastName = objuser.LastName, Birthdate = Convert.ToDateTime(objuser.Birthdate), ConfirmPassword = objuser.ConfirmPassword, DateofJoining = Convert.ToDateTime(objuser.DateofJoining), DateofLeaving = Convert.ToDateTime(objuser.DateofLeaving), DeptId = objuser.DeptId, EmailID = objuser.EmailID, EmergencyContact = objuser.EmergencyContact, EmergencyContactNumber = objuser.EmergencyContactNumber, EmployeeID = objuser.EmployeeID, JobId = objuser.JobId, Gender = objuser.Gender, IsActive = objuser.IsActive ? true : true, ManagerId = objuser.ManagerId, Mobileno = objuser.Mobileno, Password = objuser.Password, RegistrationID = objuser.RegistrationID, RoleID = objuser.RoleID, Username = objuser.Username, WorkEmail = objuser.WorkEmail, CreatedOn = DateTime.Now }; if (objuser.RegistrationID > 0) { result = _IRegistrationRepository.UpdateUser(user); } else { if (!string.IsNullOrWhiteSpace(objuser.Username)) { var isvalidUserName = _IRegistrationRepository.CheckUserNameExists(objuser.Username); if (!isvalidUserName) { result = _IRegistrationRepository.AddUser(user); } else { result = -1; } } } return(Ok(result)); }