//Get all menus (include Role's permission)
        public JsonResult GetFullMenuIncludeRolePermission(int roleID)
        {
            MenuDB menuDB = new MenuDB();

            //ReturnMenuRole x = menuDB.GetListAllMenuWithRolePermission(roleID);
            return(Json(menuDB.GetListAllMenuWithRolePermission(roleID), JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(int?id)
        {
            MenuDB db   = new MenuDB();
            Menu   menu = db.Menus.Find(id);

            db.Menus.Remove(menu);
            db.SaveChanges();
            ViewBag.Info = string.Format(
                "Menu item deleted: {0}", menu.Id);
            return(View("Index", db.Menus.ToList()));
        }
        public ActionResult CreateMenu(Menu m)
        {
            MenuDB db = new MenuDB();

            m.Date = DateTime.Now;
            db.Menus.Add(m);
            db.SaveChanges();
            if (ModelState.IsValid)
            {
                ViewBag.Info = string.Format(
                    "Menu created: {0}, Price: {1}, Category {2}", m.Text, m.Price, m.Category);
            }
            else
            {
                ViewBag.Info = "not valid";
            }
            return(View("Index", db.Menus.ToList()));
        }
        public ActionResult CheckLogin(string userid, string password)
        {
            //---------------------------------------------------------------------
            if (Request.HttpMethod == "GET")
            {
                return(RedirectToAction("Login"));
            }
            //check validation.
            string errorNotify = "";

            if (String.IsNullOrEmpty(userid))
            {
                errorNotify = " Nhập tên đăng nhập/Input UserName.";
            }
            if (String.IsNullOrEmpty(password))
            {
                errorNotify += " Nhập mật khẩu/Input password.";
            }
            if (!String.IsNullOrEmpty(errorNotify))
            {
                ViewBag.error = errorNotify;
                return(RedirectToAction("Login"));
            }

            var        passwordMd5 = SMCommon.MD5Endcoding(password.Trim()).ToLower();
            ReturnUser returnUser  = (new UserDB()).CheckLogin(userid.Trim(), passwordMd5);

            if (returnUser.Code == "01")
            {
                errorNotify += " Tên đăng nhập hoặc mật khẩu không đúng/UserName or Password is incorrect!";
            }
            if (returnUser.Code == "99")
            {
                errorNotify += " Kiểm tra lại đường truyền/Check connection.";
            }
            if (!String.IsNullOrEmpty(errorNotify))
            {
                ViewBag.error = " Lỗi đăng nhập/Error Login: "******"Login"));
            }

            //Validation is successful.
            if (returnUser.Code == "00") // exist user.
            {
                User user = returnUser.lstUser[0];
                MyShareInfo.ID           = user.ID;
                MyShareInfo.UserName     = user.UserName;
                MyShareInfo.PassWord     = user.PassWord;
                MyShareInfo.FullName     = user.FullName;
                MyShareInfo.MobileNumber = user.MobileNumber;
                MyShareInfo.FactoryID    = user.FactoryID;
                MyShareInfo.RoleID       = user.RoleID;
                //Session["UserLogin"] = user;

                Session["UserID"]    = user.ID;
                Session["UserName"]  = user.UserName;
                Session["FactoryID"] = user.FactoryID;

                #region dynamic menu by userid
                MenuDB menuDB      = new MenuDB();
                User   currentUser = new User()
                {
                    ID = Convert.ToInt32(Session["UserID"].ToString())
                };
                ReturnMenuRole returnMenuRole = menuDB.GetMenusByUserID(currentUser);
                var            menuViewModel  = new MenuViewModel
                {
                    returnMenuRole = returnMenuRole,
                    user           = currentUser
                };
                Session["MenuPermission"] = menuViewModel;
                #endregion
                //Permission
                Session["UserPermission"] = (new UserDB()).ListAllControllerName_PermissionByUserID(user.ID);
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Login"));
        }
        public JsonResult GetMenusByUserID(User user)
        {
            MenuDB menuDB = new MenuDB();

            return(Json(menuDB.GetMenusByUserID(user), JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
 /// <summary>
 /// 自定义构造函数
 /// </summary>
 public MenuFun()
 {
     baseDataModel = new MenuDB();
 }