Example #1
0
        public ActionResult Create(Role obj, string menufunctionvalues, bool SaveAndCountinue = false)
        {
            //
            ViewBag.Selected = menufunctionvalues;
            ViewBag.urlValue = url;

            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            //Gán giá trị
            obj.Id = Common.GenerateId();

            //Thêm danh sách cây menu
            if (!string.IsNullOrWhiteSpace(menufunctionvalues))
            {
                var ids = menufunctionvalues.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (ids.Any())
                {
                    foreach (var id in ids)
                    {
                        RoleMenu objRoleMenu = new RoleMenu();
                        objRoleMenu.Id     = Common.GenerateId();
                        objRoleMenu.RoleId = obj.Id;
                        objRoleMenu.MenuId = id;
                        _RoleMenuService.Create(objRoleMenu);
                    }
                }
            }

            //Thực hiện thêm mới
            var result = _RoleService.Create(obj);

            if (result.isSuccess)
            {
                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(obj));
            }
        }
        public ActionResult Create(Role obj, string menufunctionvalues, bool SaveAndCountinue = false, string group = "")
        {
            if (String.IsNullOrEmpty(obj.RoleName) || String.IsNullOrWhiteSpace(obj.RoleName))
            {
                ModelState.AddModelError("", FunctionHelper.GetLocalizeDictionary("Home", "notification")["Role_Name"]);
                ViewBag.Selected = "";
                ViewBag.GroupID  = group;

                ViewBag.MenuFunctionList = _MenuFunctionService.GetAllActive().ToList();
                return(View(obj));
            }
            //
            ViewBag.Selected = menufunctionvalues;
            ViewBag.GroupID  = group;

            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            //Gán giá trị
            obj.Id = Common.GenerateId();

            //Thêm danh sách cây menu
            if (!string.IsNullOrWhiteSpace(menufunctionvalues))
            {
                var ids = menufunctionvalues.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (ids.Any())
                {
                    foreach (var id in ids)
                    {
                        RoleMenu objRoleMenu = new RoleMenu();
                        objRoleMenu.Id     = Common.GenerateId();
                        objRoleMenu.RoleId = obj.Id;
                        objRoleMenu.MenuId = id;
                        _RoleMenuService.Create(objRoleMenu);
                    }
                }
            }

            //Thực hiện thêm mới
            var result = _RoleService.Create(obj);

            if (result)
            {
                var mes = new MessageReport();
                mes.isSuccess = true;
                mes.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["Role_New"];

                var name = FunctionHelper.getCurrentGroup(group);
                WriteLog.Write(mes, GetCurrentUser.GetUser(), obj.Id, obj.RoleName, "Role", name, ActionConfigO.Create);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"];
                    return(RedirectToAction("Create", new { group = group }));
                }
                return(RedirectToAction("Index", new { group = group }));
            }
            else
            {
                return(View(obj));
            }
        }