コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public CreateUserResponse CreateUser(CreateUser user)
 {
     try
     {
         return(CommandService.CreateUser(user));
     }
     catch (Exception ex)
     {
         Logger.LogError(ex);
         throw new FaultException(ex.Message);
     }
 }
コード例 #3
0
 public async Task <IHttpActionResult> CreateUser([FromBody] CreateUser request)
 {
     try
     {
         return(Ok(await CommandService.CreateUser(request)));
     }
     catch (Exception ex)
     {
         Logger.LogError(ex);
         // Can be fine tuned to throw a general exception instead of sending the server exception
         return(InternalServerError(ex));
     }
 }