示例#1
0
        public ActionResult Create(WebManageUsers entity, FormCollection form)
        {
            if (GetRole == null || GetDept == null)
            {
                ModelState.AddModelError("", "请把表单填写完整...");
                return(View());
            }

            if (userRepository.Find(i => i.LoginName == entity.LoginName) != null)
            {
                ModelState.AddModelError("", "名称不能重复...");
                return(View());
            }

            entity.Operator       = "";
            entity.WebManageRoles = roleRepository.GetModel(i => GetRole.Contains(i.Id)).ToList();
            entity.WebDepartments = departmentsRepository.GetModel(i => GetDept.Contains(i.Id)).ToList();
            if (ModelState.IsValid)
            {
                entity.Password = Lind.DDD.Utils.Encryptor.Utility.EncryptString(entity.Password, Utils.Encryptor.Utility.EncryptorType.MD5);
                userRepository.Insert(entity);
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "请把表单填写完整...");
                return(View(entity));
            }
        }
示例#2
0
        public ActionResult Edit(int id, WebManageUsers entity, FormCollection form)
        {
            ModelState.Remove("Password");
            if (userRepository.Find(i => i.LoginName == entity.LoginName && i.Id != entity.Id) != null)
            {
                ModelState.AddModelError("", "名称不能重复...");
                return(View(new WebManageUsers {
                    Id = id
                }));
            }

            var old = userRepository.GetModel()
                      .Include(i => i.WebDepartments)
                      .Include(i => i.WebManageRoles)
                      .FirstOrDefault(i => i.Id == id);

            old.WebManageRoles = roleRepository.GetModel(i => GetRole.Contains(i.Id)).ToList();
            old.WebDepartments = departmentsRepository.GetModel(i => GetDept.Contains(i.Id)).ToList();
            old.LoginName      = entity.LoginName;
            old.ThridUserId    = entity.ThridUserId;
            old.RealName       = entity.RealName;
            old.Mobile         = entity.Mobile;
            old.Email          = entity.Email;
            old.Description    = entity.Description;
            if (ModelState.IsValid)
            {
                userRepository.Update(old);
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "请把表单填写完整...");
                return(View(new WebManageUsers {
                    Id = id
                }));
            }
        }