Пример #1
0
        public ActionResult UserEdit(UserEditViewModel model)
        {
            if (!ViewBag.IsAdmin)
            {
                return RedirectToAction("Index", "Home");
            }

            if (string.IsNullOrWhiteSpace(model.PassWord))
            {
                ModelState.AddModelError("PassWord", "密码不能为空!");
                model.CountryList = new SelectList(DbContext.T_Country, "Id", "Country", model.Remark);
                var statusList = new List<SelectListItem>
            {
                new SelectListItem()
                {
                    Text = "超级管理员",
                    Value = "1"
                },
                new SelectListItem()
                {
                    Text = "管理员",
                    Value = "2"
                }
            };
                model.RoleList = new SelectList(statusList, "Value", "Text", model.RoleId);
                return View(model);
            }

            var user = model.UserId == -1 ? new T_Users() : DbContext.T_Users.First(item => item.UserId == model.UserId);

            user.Mobile = model.Mobile;
            user.Email = model.EmailAddress;
            user.Remark = model.Remark;
            user.RoleId = model.RoleId;
            user.UserName = model.UserName;
            user.Pwd = Global.GetMd5(model.PassWord);
            user.RoleId = model.RoleId;

            if (model.UserId == -1)
            {
                user.Status = 1;
                user.RegTime = DateTime.Now;
                DbContext.T_Users.Add(user);
            }

            DbContext.SaveChanges();

            return RedirectToAction("UserManage", "Admin");
        }
Пример #2
0
        public ActionResult UserEdit(string id)
        {
            if (!ViewBag.IsAdmin)
            {
                return RedirectToAction("Index", "Home");
            }

            WdContext.SiteMapMenu.ActionMenu.Name = "编辑用户";
            var model = new UserEditViewModel();
            if (string.IsNullOrWhiteSpace(id))
            {
                WdContext.SiteMapMenu.ActionMenu.Name = "新增用户";
                model.UserId = -1;
                model.IsNew = true;
                model.RegTime = DateTime.Now;
                model.LastTime = DateTime.Now;
                model.Status = 1;
            }
            else
            {
                var user = DbContext.T_Users.First(item => item.UserId.ToString() == id);
                model.UserId = user.UserId;
                model.Mobile = user.Mobile;
                model.EmailAddress = user.Email;
                model.Remark = user.Remark;
                model.Status = user.Status;
                model.UserName = user.UserName;
                model.RoleId = user.RoleId;
            }

            ViewBag.ReturnUrl = "/Admin/UserManage";

            model.CountryList = new SelectList(DbContext.T_Country, "Id", "Country", model.Remark);

            var statusList = new List<SelectListItem>
            {
                new SelectListItem()
                {
                    Text = "超级管理员",
                    Value = "1"
                },
                new SelectListItem()
                {
                    Text = "管理员",
                    Value = "2"
                }
            };
            model.RoleList = new SelectList(statusList, "Value", "Text", model.RoleId);

            return View(model);
        }