Ejemplo n.º 1
0
 public IActionResult EditRole(SysRole model)
 {
     ModelState.Remove("Id");
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     model.Name = model.Name.Trim();
     if (model.Id == Guid.Empty)
     {
         model.Id           = Guid.NewGuid();
         model.CreationTime = DateTime.Now;
         model.Creator      = _workContext.CurrentUser().Id;
         _sysRoleService.InsertRole(model);
     }
     else
     {
         model.ModifiedTime = DateTime.Now;
         model.Modifier     = _workContext.CurrentUser().Id;
         _sysRoleService.UpdateRole(model);
     }
     _sysRoleService.SaveChanges();
     return(RedirectToAction("index", "role"));
 }
Ejemplo n.º 2
0
 public IActionResult EditUser(SysUser model, string sysRole, string returnUrl = null)
 {
     ViewBag.ReturnUrl   = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("userIndex");
     ViewBag.SysRoleList = _sysRoleService.GetAllRoles().Select(o => new SelectListItem()
     {
         Value = o.Id.ToString(), Text = o.Name, Selected = (o.Id.ToString() == sysRole)
     }).ToList();
     ModelState.Remove("Id");
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (!string.IsNullOrEmpty(model.MobilePhone))
     {
         model.MobilePhone = StringUitls.toDBC(model.MobilePhone);
     }
     model.Name = model.Name.Trim();
     if (model.Id == Guid.Empty)
     {
         model.Id           = Guid.NewGuid();
         model.CreationTime = DateTime.Now;
         model.Salt         = EncryptorHelper.CreateSaltKey();
         model.Account      = StringUitls.toDBC(model.Account);
         model.Enabled      = true;
         model.IsAdmin      = false;
         model.Password     = EncryptorHelper.GetMD5(model.Account + model.Salt);
         model.Creator      = _workContext.CurrentUser().Id;
         _sysUserService.InsertSysUser(model);
     }
     else
     {
         model.ModifiedTime = DateTime.Now;
         model.Modifier     = _workContext.CurrentUser().Id;
         _sysUserService.UpdateSysUser(model);
     }
     if (!string.IsNullOrEmpty(sysRole))
     {
         _sysUserRoleService.InsertOrUpdateSysUserRole(model.Id, new Guid(sysRole));
     }
     return(Redirect(ViewBag.ReturnUrl));
 }