public HttpResponseMessage Create(UserModel user) { try { user.Id = _userCommandService.CreateUser(user.PrimaryAgencyId, user.Username, user.Password, user); if (user.IsActive) { _userCommandService.EnableUser(user.Id); } else { _userCommandService.DisableUser(user.Id); } _userCommandService.AssignRoles(user.Id, user.Roles.Select(r => r.RoleId).ToList()); return(Request.CreateResponse(user)); } catch (DuplicateUsernameException ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "A duplicate username exists. Please enter a new username.", ex)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionMessages.UnexpectedErrorPleaseTryAgain, ex)); } }