예제 #1
0
        private void toolStripMenuItemUpdate_Click(object sender, EventArgs e)
        {
            Form f;

            switch (this.DisplayFormTypeProperty)
            {
            case (int)Manage.USER:
                f = new UpdateUserForm();
                break;

            case (int)Manage.HOST:
                f = new UpdateHostForm();
                break;

            case (int)Manage.GROUP:
                f = new UpdateGroupForm();
                break;

            case (int)Manage.PROCESSLIST:
                f = new UpdateProcessListForm();
                break;

            default:
                f = new UpdateUserForm();
                break;
            }
            f.ShowDialog();
        }
예제 #2
0
        public virtual IActionResult UpdateUser([FromRoute] int id, [FromBody] UpdateUserForm updateUserForm)
        {
            User userForUpdate = userManager.FindByIdAsync(id.ToString()).Result;

            if (userForUpdate == null)
            {
                return(NotFound(new ResponseMessage {
                    Title = $"خطای 404", Descripton = $".متاسفانه نتوانستیم کاربر با شناسه {id} را پیدا کنیم"
                }));
            }
            if (string.IsNullOrEmpty(updateUserForm.UserName.NullIfEmpty()) ||
                (string.IsNullOrEmpty(updateUserForm.UserName.NullIfEmpty()) && (userForUpdate.Email != updateUserForm.Email)))
            {
                updateUserForm.UserName = updateUserForm.Email;
            }
            mapper.Map(updateUserForm, userForUpdate);

            IdentityResult updateRoleResult = userManager.UpdateAsync(userForUpdate).Result;

            if (!updateRoleResult.Succeeded)
            {
                foreach (var message in updateRoleResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, message.Description);
                }
                ResponseMessage responseMessage = new ResponseMessage();
                responseMessage.Title      = "مقادیر ارسالی صحیح نیستند";
                responseMessage.Descripton = ModelState.GetSingleLineErrorMessages();
                return(BadRequest(responseMessage));
            }

            return(NoContent());
        }
예제 #3
0
        public void showUpdateUserForm(AdminDashBoard adminDashBoard, User user)
        {
            UpdateUserForm updateUserForm = new UpdateUserForm(adminDashBoard, user);

            adminDashBoard.Hide();
            updateUserForm.ShowDialog();
        }
예제 #4
0
        /// <summary>
        /// When user clicks on BtnAddImage
        /// </summary>
        /// <param name="sender">System.Windows.Forms.Button</param>
        /// <param name="e">System.Windows.Forms.MouseEventArgs</param>
        private void BtnUpdateProfile_Click(object sender, EventArgs e)
        {
            Hide();
            UpdateUserForm updateUserForm = new UpdateUserForm(ref authentifiedUser);

            updateUserForm.Show();
        }
예제 #5
0
        public async Task Test5()
        {
            await SeedData();

            var updateForm = new UpdateUserForm()
            {
                Id        = 1,
                Age       = 40,
                Email     = "*****@*****.**",
                FirstName = "Mike",
                LastName  = "Emil",
                Password  = "******"
            };

            var response0 = await Client.PutAsync("/api/users/1", new StringContent(JsonConvert.SerializeObject(updateForm), Encoding.UTF8, "application/json"));

            response0.StatusCode.Should().BeEquivalentTo(StatusCodes.Status200OK);

            var response1 = await Client.GetAsync("/api/users/1");

            response1.StatusCode.Should().BeEquivalentTo(StatusCodes.Status200OK);

            var user = JsonConvert.DeserializeObject <User>(response1.Content.ReadAsStringAsync().Result);

            response1.StatusCode.Should().BeEquivalentTo(StatusCodes.Status200OK);
            user.Age.Should().Be(40);
            user.Password.Should().Be("0000000");
        }
예제 #6
0
        public async Task <ActionResult <User> > UpdateUser(UpdateUserForm user)
        {
            var Id = Convert.ToInt32(GetClaim("id"));

            user = await _userService.UpdateUser(Id, user);

            return(Ok(user));
        }
예제 #7
0
        public async Task <UpdateUserForm> UpdateUser(int Id, UpdateUserForm user)
        {
            var item = ctx.Users.Where(c => c.Id == Id).SingleOrDefault();

            _mapper.Map(user, item);

            await ctx.SaveChangesAsync();

            return(user);
        }
 public ActionResult UpdateUser([ModelBinder(typeof(UserFormModelBinder))] UpdateUserForm updateUserForm)
 {
     if (repository != null)
     {
         repository.UpdateUser(updateUserForm);
         HttpContext.Cache[string.Format("{0}'s CurrentPermissions", updateUserForm.UserName)] = updateUserForm.CurrentPermissions;
         ViewBag.Permissions        = MVCEveining.Helpers.EnumHelpers.ToDictionary <MVCEveining.ViewModels.LoginForm.Permissions>();
         TempData["SuccessMessage"] = "User updated successfully.";
     }
     return(RedirectToAction("UpdateUser", new { UserId = updateUserForm.UserName }));
 }
        // [PermissionRequired(MVCEveining.ViewModels.Users.Permissions.Update_Users)]
        public ActionResult UpdateUser(string userId)
        {
            var user = repository.GetUser(userId);

            if (user == null)
            {
                return(View("UserNotFound"));
            }

            var userForm = new UpdateUserForm(user);

            ViewBag.Permissions = MVCEveining.Helpers.EnumHelpers.ToDictionary <MVCEveining.ViewModels.LoginForm.Permissions>();
            return(View(userForm));
        }
예제 #10
0
        public void UpdateUser(UpdateUserForm updateUserForm)
        {
            using (var connection = new SqlConnection(connectionString))
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"UPDATE  users SET 
                                        CurrentPermissions = @CurrentPermissions                                      
                                        WHERE UserName = @UserName";

                    command.Parameters.AddWithValue("@UserName", updateUserForm.UserName);

                    command.Parameters.AddWithValue("@CurrentPermissions", updateUserForm.CurrentPermissions);

                    connection.Open();

                    command.ExecuteNonQuery();
                }

            //EventsRepository.Create("User Update.", userForm.Id, HttpContext.Current.User.Identity.Name);
        }
예제 #11
0
        public ActionResult UpdateProfile(UpdateUserForm form)
        {
            if (ModelState.IsValid)
            {
                User UpdatedUser = new User(
                    SessionManager.User.ID,
                    form.FirstName ?? SessionManager.User.FirstName,
                    form.LastName ?? SessionManager.User.LastName,
                    form.Email ?? SessionManager.User.Email, ""
                    );

                User NewUser = ClientServicesLocator.Instance.Users.UpdateUser(UpdatedUser);

                if (NewUser != null)
                {
                    SessionManager.User = NewUser;
                }

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("UpdateProfile"));
        }
예제 #12
0
 public void showAdminDashBoard(AdminDashBoard adminDashboard, UpdateUserForm updateUserForm)
 {
     updateUserForm.Close();
     adminDashboard.Show();
 }
예제 #13
0
        public IHttpActionResult Update(uint id, [FromBody] UpdateUserForm form)
        {
            Dictionary <string, string> errorList;
            uint currentUserId = Convert.ToUInt32(RequestContext.Principal.Identity.Name);

            if (!ModelState.IsValid)
            {
                errorList = AppUtils.Validation.GetErrorDictionary(ModelState);
                return(Content(
                           HttpStatusCode.BadRequest,
                           new ResponseWrapper <object>(HttpStatusCode.BadRequest, errorList)
                           ));
            }
            User user = new User();

            if (!user.DAL_Load(id))
            {
                return(NotFound());
            }

            user.Username     = form.Username;
            user.IsActive     = form.IsActive;
            user.FullName     = form.FullName;
            user.EmailAddress = form.EmailAddress;
            user.Designation  = form.Designation;
            user.MobileNumber = form.MobileNumber;
            user.ModifiedBy   = currentUserId;

            List <UserRole> userRoles             = UserRole.DAL_Load(id, null, null, null, null);
            List <uint>     willRetainUserRoleIds = userRoles
                                                    .FindAll(item => form.Roles.Exists(nItem => nItem == item.RoleId))
                                                    .ConvertAll(item => item.UserRoleId);
            List <uint> willAddRoleIds = form.Roles.FindAll(item => !userRoles.Exists(nItem => nItem.RoleId == item));

            var conn  = AppSetting.Db.OpenConnection();
            var trans = conn.BeginTransaction();

            try
            {
                if (user.DAL_Update(conn, trans) &&
                    UserRole.DAL_DeleteByUserId(conn, trans, user.UserId, string.Join(",", willRetainUserRoleIds)))
                {
                    bool hasErrorTransaction = willAddRoleIds.Exists(
                        item => !new UserRole
                    {
                        UserId    = user.UserId,
                        RoleId    = item,
                        CreatedBy = currentUserId,
                    }.DAL_AddExisting(conn, trans)
                        );

                    if (!hasErrorTransaction)
                    {
                        trans.Commit();
                        return(Ok(new ResponseWrapper <bool>(HttpStatusCode.OK, true)));
                    }
                }
                trans.Rollback();
            }
            catch (Exception)
            {
                trans.Rollback();
            }
            finally
            {
                AppSetting.Db.CloseConnection(ref conn);
            }

            ModelState.AddModelError("", "Failed to process your request");
            errorList = AppUtils.Validation.GetErrorDictionary(ModelState);
            return(Content(
                       HttpStatusCode.BadRequest,
                       new ResponseWrapper <object>(HttpStatusCode.BadRequest, errorList)
                       ));
        }
예제 #14
0
 public ActionResult Update(UpdateUserForm form)
 {
     ServiceClientLocator.Instance.Utilisateurs.Update(new Utilisateurs(SessionManager.Users.UsersID, form.Nom, form.Prenom, form.Email));
     return(RedirectToAction("Update", "Member"));
 }
예제 #15
0
        /// <summary>
        /// When admins click on update users page
        /// </summary>
        /// <param name="sender">System.Windows.Forms.Button</param>
        /// <param name="e">System.Windows.Forms.MouseEventArgs</param>
        private void UpdateUserBtn_Click(object sender, EventArgs e)
        {
            UpdateUserForm updateUserForm = new UpdateUserForm();

            updateUserForm.Show();
        }