Example #1
0
        public ActionResult Create(MenuFunction obj, bool SaveAndCountinue = false, string group = "")
        {
            if (String.IsNullOrEmpty(obj.MenuName) || String.IsNullOrWhiteSpace(obj.MenuName))
            {
                ModelState.AddModelError("", FunctionHelper.GetLocalizeDictionary("Home", "notification")["menu_Name"]);
                ViewBag.DDLMenu     = GetMenuList();
                ViewBag.IconList    = ListViewCustom.GetListIcon("~/Templates/AwesomeIcon.xml");
                ViewBag.DDLMenuType = FunctionHelper.MenuType();
                ViewBag.GroupID     = group;
                return(View(obj));
            }
            //ViewBag
            ViewBag.DDLMenu     = GetMenuList();
            ViewBag.IconList    = ListViewCustom.GetListIcon("~/Templates/AwesomeIcon.xml");
            ViewBag.DDLMenuType = FunctionHelper.MenuType();

            ViewBag.GroupID = group;

            if (ModelState.IsValid)
            {
                obj.Id             = Common.GenerateId();
                obj.ControllerName = obj.ControllerName != null ? obj.ControllerName : string.Format("controller_{0}", obj.Id);
                obj.ActionName     = obj.ActionName != null ? obj.ActionName : string.Format("action_{0}", obj.Id);
                obj.Url            = string.Format("/{0}/{1}", obj.ControllerName, obj.ActionName);
                obj.Deleted        = false;
                bool isSuccess = _MenuFunctionService.Create(obj);
                if (isSuccess)
                {
                    //For cache
                    CacheLayer.ClearAll();

                    //Write report
                    MessageReport report = new MessageReport(true, FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"]);
                    WriteLog.Write(report, GetCurrentUser.GetUser(), obj.Id, obj.MenuName, "MenuFunction");

                    if (SaveAndCountinue)
                    {
                        TempData["Success"] = FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"];
                        return(RedirectToAction("Create", "MenuFunction", new { controllername = obj.ControllerName, parentid = obj.ParentId, menytype = obj.MenuType, grouplist = obj.MenuGroupListId, group = group, ordernu = obj.OrderNumber + 1 }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", new { group = group }));
                    }
                }
                else
                {
                    ModelState.AddModelError("", FunctionHelper.GetLocalizeDictionary("Home", "notification")["ErMenu"]);
                    return(View(obj));
                }
            }

            return(View());
        }
        public ActionResult Create(MenuFunction obj, bool SaveAndCountinue = false)
        {
            //ViewBag
            ViewBag.DDLMenu     = GetMenuList();
            ViewBag.IconList    = ListViewCustom.GetListIcon("~/Templates/AwesomeIcon.xml");
            ViewBag.DDLMenuType = FunctionHelper.MenuType();

            ViewBag.urlValue = url;

            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            obj.Id             = Common.GenerateId();
            obj.ControllerName = obj.ControllerName != null ? obj.ControllerName : string.Format("controller_{0}", obj.Id);
            obj.ActionName     = obj.ActionName != null ? obj.ActionName : string.Format("action_{0}", obj.Id);
            obj.Url            = string.Format("/{0}/{1}", obj.ControllerName, obj.ActionName);
            obj.IsDeleted      = false;

            var report = _MenuFunctionService.Create(obj);

            if (report.isSuccess)
            {
                //For cache
                CacheLayer.ClearAll();

                if (SaveAndCountinue)
                {
                    TempData["Success"] = report.Message;

                    return(RedirectToAction("Create", "MenuFunction", new { controllername = obj.ControllerName, parentid = obj.ParentId, menytype = obj.MenuType, ordernu = obj.OrderNumber + 1 }));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Có lỗi xảy ra trong quá trình khởi tạo.");
                return(View(obj));
            }
        }