Exemple #1
0
        public ActionResult EditUser(Entities.SysUser model, string returnUrl = null)
        {
            ModelState.Remove("Id");
            ViewBag.ReturnUrl = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("userIndex");
            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.Trim());
                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);
            }
            return(Redirect(ViewBag.ReturnUrl));
        }
Exemple #2
0
        public ActionResult Usermessages(Entities.SysUserMessage modela, string returnUrl = null)
        {
            ModelState.Remove("Id");
            ViewBag.ReturnUrl = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("mainIndex");
            var model = _sysUserService.getById(WorkContext.CurrentUser.Id);

            if (!ModelState.IsValid)
            {
                return(View(modela));
            }
            if (!String.IsNullOrEmpty(modela.MobilePhone))
            {
                model.MobilePhone = StringUitls.toDBC(modela.MobilePhone);
            }
            if (!String.IsNullOrEmpty(modela.Email))
            {
                model.Email = StringUitls.toDBC(modela.Email);
            }
            //model.Name = model.Name.Trim();

            if (model.Id == Guid.Empty)
            {
                return(Redirect(ViewBag.ReturnUrl));
            }
            else
            {
                model.ModifiedTime = DateTime.Now;
                model.Modifier     = WorkContext.CurrentUser.Id;
                _sysUserService.updateUsermessage(model);
            }
            return(Redirect(ViewBag.ReturnUrl));
        }
 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));
 }
Exemple #4
0
 public ActionResult EditAccount(Entities.SysUser model, string returnUrl = null)
 {
     ViewBag.ReturnUrl = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("mainIndex");
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (!string.IsNullOrEmpty(model.MobilePhone))
     {
         model.MobilePhone = StringUitls.toDBC(model.MobilePhone);
     }
     model.Name         = model.Name.Trim();
     model.ModifiedTime = DateTime.Now;
     model.Modifier     = WorkContext.CurrentUser.Id;
     _sysUserService.updateSysUser(model);
     if (!string.IsNullOrEmpty(model.Password))
     {
         _sysUserService.changePassword(model.Id, model.Password);
     }
     return(Redirect(ViewBag.ReturnUrl));
 }