Exemple #1
0
        public IHttpActionResult PostUserAccount(UserAccountModel user)
        {
            if (user == null)
            {
                return(BadRequest("user account cannot be found in the request body."));
            }
            try
            {
                var enryptedPassword = user.Password.Hashstring();

                var modelUser = new UserAccountModel()
                {
                    Email           = user.Email,
                    FullName        = user.FullName,
                    IsActive        = true,
                    IsAdministrator = user.IsAdministrator,
                    Mobile          = user.Mobile,
                    Password        = enryptedPassword,
                    //UserId = user.UserId,
                    UserName     = user.UserName,
                    UserRolesIds = user.UserRolesIds,
                    CreatedDate  = DateTime.Now,
                    RoleId       = 1
                };
                var newUserAccount = authService.CreateUserAccount(modelUser.AutoMapObject <UserAccountModel, DB.UsersAccount>());
                if (newUserAccount != null && newUserAccount.UserId > 0)
                {
                    authService.AddUserRoles(newUserAccount.UserId, newUserAccount.UserRolesIds);
                }

                var usersAccounts = authService.GetAllUsersAccounts();
                var html          = Helpers.RenderPartial("~/Views/Shared/Partial/UsersAccountsTable.cshtml", usersAccounts);
                return(Ok(html));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }