Exemple #1
0
        public IActionResult AdminProcessEditUser(AdminEditModel AdminEditAttempt)
        {
            int?SessionId  = HttpContext.Session.GetInt32("id");
            int?Permission = HttpContext.Session.GetInt32("permission");

            if (SessionId != null && Permission != null && Permission == 9)
            {
                ViewBag.LoggedIn   = true;
                ViewBag.Name       = HttpContext.Session.GetString("name");
                ViewBag.Id         = SessionId;
                ViewBag.Permission = Permission;
            }
            else
            {
                return(RedirectToAction("Dashboard"));
            }

            if (ModelState.IsValid && (AdminEditAttempt.PermissionLevel == 0 || AdminEditAttempt.PermissionLevel == 9))
            {
                User EditUser = _context.users.SingleOrDefault(user => user.UserId == AdminEditAttempt.UserId);

                EditUser.FirstName       = AdminEditAttempt.FirstName;
                EditUser.LastName        = AdminEditAttempt.LastName;
                EditUser.Email           = AdminEditAttempt.Email;
                EditUser.Description     = AdminEditAttempt.Description;
                EditUser.PermissionLevel = AdminEditAttempt.PermissionLevel;

                return(RedirectToAction("Dashboard"));
            }


            return(View("AdminEditUser", AdminEditAttempt));
        }
Exemple #2
0
        public async Task OnGetAsync(string Id)
        {
            if (string.IsNullOrEmpty(Id))
            {
                ModelState.AddModelError("", "شناسه وارده نام عتبر است");
            }

            Model = new AdminEditModel();
            CustomUser user = await UserManager.FindByIdAsync(Id);

            Model = Mapper.Map(user, Model);
            List <string> Roles   = UserManager.GetRolesAsync(user).GetAwaiter().GetResult().ToList();
            List <string> AllRole = await RoleManager.Roles.Select(c => c.Name).AsNoTracking().ToListAsync();

            // AllRole.Union(Roles);
            Model.SelectedRoles = AllRole.Select(c => new RoleModel {
                Name = c, Checked = false
            }).ToList();
            Model.SelectedRoles.ForEach(c =>
            {
                if (Roles.Contains(c.Name))
                {
                    c.Checked = true;
                }
            });
        }
Exemple #3
0
 public ActionResult AdminEdit(AdminEditModel model)
 {
     if (string.IsNullOrEmpty(model.Name))
     {
         return(Json(new AjaxResult {
             Status = "0", Msg = "管理员名不能为空"
         }));
     }
     if (string.IsNullOrEmpty(model.Description))
     {
         return(Json(new AjaxResult {
             Status = "0", Msg = "管理员描述不能为空"
         }));
     }
     if (model.RoleIds == null)
     {
         return(Json(new AjaxResult {
             Status = "0", Msg = "角色必须选择"
         }));
     }
     if (!adminService.Update(model.Id, model.Name, model.Mobile, model.Description, model.Password, model.RoleIds))
     {
         return(Json(new AjaxResult {
             Status = "0", Msg = "管理员用户编辑失败"
         }));
     }
     return(Json(new AjaxResult {
         Status = "1", Data = "/admin/system/adminmanager"
     }));
 }
        private void Edit(AdminDisplayModel adminDisplayModel)
        {
            AdminEditModel admin = new AdminEditModel
            {
                FirstName   = adminDisplayModel.FirstName,
                LastName    = adminDisplayModel.LastName,
                PhoneNumber = adminDisplayModel.PhoneNumber,
                Login       = adminDisplayModel.Login
            };

            AdminInfoViewModel viewModel = new AdminInfoViewModel(admin);
            AdminInfoControl   control   = new AdminInfoControl(viewModel);
            Window             window    = WindowFactory.CreateByContentsSize(control);

            viewModel.AdminEdited += (s, e) =>
            {
                AdminEditModel adminEditModel = e.Admin;
                AdminEditDTO   adminEditDTO   = Mapper.Map <AdminEditModel, AdminEditDTO>(adminEditModel);

                using (IAdminService service = factory.CreateAdminService())
                {
                    ServiceMessage serviceMessage = service.Update(adminEditDTO);
                    RaiseReceivedMessageEvent(serviceMessage);

                    if (serviceMessage.IsSuccessful)
                    {
                        window.Close();
                        Notify();
                    }
                }
            };

            window.Show();
        }
Exemple #5
0
 public ActionResult EditAdminSubmit(AdminEditModel model)
 {
     if (model.isValid())
     {
         return(View(model));
     }
     return(View(model));
 }
        private void RaiseAdminEditedEvent(AdminEditModel admin)
        {
            var handler = AdminEdited;

            if (handler != null)
            {
                AdminEditEventArgs e = new AdminEditEventArgs(admin);
                handler(this, e);
            }
        }
        public AdminInfoViewModel(AdminEditModel admin)
        {
            this.admin        = admin;
            this.adminForEdit = new AdminEditModel
            {
                FirstName   = admin.FirstName,
                LastName    = admin.LastName,
                PhoneNumber = admin.PhoneNumber,
                Login       = admin.Login
            };

            this.SaveChangesCommand = new DelegateCommand(() => RaiseAdminEditedEvent(adminForEdit), CanSave);
            this.UndoCommand        = new DelegateCommand(Undo, obj => IsDirty());
        }
        public IActionResult EditAdmin(string id)
        {
            //AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);
            AppUser user = _context.Users.FirstOrDefault(x => x.Id == id.ToString());

            AdminEditModel admin = new AdminEditModel()
            {
                FullName = user.FullName,
                UserName = user.UserName,
                Id       = user.Id,
            };

            return(View(admin));
        }
        public async Task <IActionResult> EditAdmin(AdminEditModel admin)
        {
            //AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);
            AppUser user = _context.Users.FirstOrDefault(x => x.Id == admin.Id);


            if (_userManager.Users.Any(x => x.UserName == admin.UserName && x.Id != user.Id))
            {
                ModelState.AddModelError("UserName", "UserName already taken!");
                return(View());
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            user.UserName = admin.UserName;
            user.FullName = admin.FullName;


            if (!string.IsNullOrWhiteSpace(admin.Password))
            {
                if (string.IsNullOrWhiteSpace(admin.CurrentPassword))
                {
                    ModelState.AddModelError("CurrentPassword", "CurrentPassword can not be emtpy");
                    return(View());
                }

                var result = await _userManager.ChangePasswordAsync(user, admin.CurrentPassword, admin.Password);

                if (!result.Succeeded)
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError("", item.Description);
                    }

                    return(View());
                }
            }
            await _userManager.UpdateAsync(user);

            //await _signInManager.SignInAsync(user, true);
            return(RedirectToAction("getadmins"));
        }
Exemple #10
0
 public ActionResult EditAdmin(AdminEditModel model)
 {
     AdminHelper.UpdateAdminPartial(model.Id, model.Email, string.Join(",", model.Roles), User.IsInRole(Roles.CanSetAdminRole.ToString()));
     return(RedirectToAction("AdminsList"));
 }
 public AdminEditEventArgs(AdminEditModel admin)
 {
     this.Admin = admin;
 }