コード例 #1
0
 public ActionResult Delete(int id)
 {
     User user;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IUserRep userRep = new UserRep(unitOfWork);
         user = userRep.FindById(id);
         if (user != null)
         {
             if (Brilliantech.Tsk.Manage.WebApp.Util.CustomMembershipProvider.CanEdit(user.Name))
             {
                 return View(user);
             }
             else
             {
                 TempData["Message"] = "初始管理员,不可以删除";
                 return RedirectToAction("Index");
             }
         }
         else
         {
             return RedirectToAction("Index");
         }
     }
 }
コード例 #2
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            User user = null;
            try
            {
                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserRep userRep = new UserRep(unitOfWork);
                    user = userRep.FindById(id);
                    userRep.Delete(user);
                    unitOfWork.Submit();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View(user);
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                User user;

                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserRep userRep = new UserRep(unitOfWork);
                    user = userRep.FindById(id);

                    if (Brilliantech.Tsk.Manage.WebApp.Util.CustomMembershipProvider.CanEdit(user.Name))
                    {
                        ViewData["Role"] = new SelectList(UserRoleModel.UserRoleList(), "Key", "Name", user.Role);
                        if (collection.Get("Password").Trim().Length < CustomMembershipProvider.MinRequiredPasswordLength)
                        {
                            ViewBag.Message = "密码长度小于" + CustomMembershipProvider.MinRequiredPasswordLength;
                            return View(user);
                        }
                        else
                        {
                            user.Password = collection.Get("Password").Trim();
                            user.Role = collection.Get("Role");
                            user.Email = collection.Get("Email");
                            unitOfWork.Submit();
                            return RedirectToAction("Index");
                        }
                    }
                    else
                    {
                        TempData["Message"] = "初始管理员,不可以编辑";
                        return RedirectToAction("Index");
                    }
                }
            }
            catch
            {
                return View();
            }
        }