public bool EditValidationCheck(int?subMenuId, EditSubMenuMasterViewModel editsubMenu)
        {
            var result = (from submenu in _frapperDbContext.SubMenuMasters.AsNoTracking()
                          where submenu.SubMenuId == subMenuId
                          select submenu).SingleOrDefault();

            if (result != null && (editsubMenu.MenuId == result.MenuId &&
                                   editsubMenu.MenuCategoryId == result.MenuCategoryId &&
                                   editsubMenu.RoleId == result.RoleId &&
                                   editsubMenu.SubMenuName == result.SubMenuName))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public IActionResult Edit(EditSubMenuMasterViewModel subMenuMasterVm)
        {
            try
            {
                subMenuMasterVm.ListofRoles        = _roleQueries.ListofRoles();
                subMenuMasterVm.ListofMenuCategory = new List <SelectListItem>()
                {
                    new SelectListItem()
                    {
                        Value = "",
                        Text  = "-----Select-----"
                    }
                };
                subMenuMasterVm.ListofMenus = new List <SelectListItem>()
                {
                    new SelectListItem()
                    {
                        Value = "",
                        Text  = "-----Select-----"
                    }
                };

                if (ModelState.IsValid)
                {
                    if (_subMenuMasterQueries.EditValidationCheck(subMenuMasterVm.SubMenuId, subMenuMasterVm))
                    {
                        SubMenuMaster subMenuMaster = new SubMenuMaster()
                        {
                            SubMenuId      = subMenuMasterVm.SubMenuId,
                            RoleId         = subMenuMasterVm.RoleId,
                            MenuCategoryId = subMenuMasterVm.MenuCategoryId,
                            MenuId         = subMenuMasterVm.MenuId,
                            Status         = subMenuMasterVm.Status,
                            ActionMethod   = subMenuMasterVm.ActionMethod,
                            Area           = subMenuMasterVm.Area,
                            ControllerName = subMenuMasterVm.ControllerName,
                            SubMenuName    = subMenuMasterVm.SubMenuName,
                            CreatedOn      = DateTime.Now,
                        };
                        subMenuMaster.CreatedBy = Convert.ToInt64(HttpContext.Session.Get <string>(AllSessionKeys.UserId));
                        _unitOfWorkEntityFramework.SubMenuMasterCommand.Update(subMenuMaster);
                        _unitOfWorkEntityFramework.Commit();

                        _notificationService.SuccessNotification("Message", "SubMenu was Updated Successfully!");
                        return(RedirectToAction("Index", "SubMenuMaster"));
                    }
                    else if (_subMenuMasterQueries.CheckSubMenuNameExists(subMenuMasterVm.SubMenuName, subMenuMasterVm.MenuId,
                                                                          subMenuMasterVm.RoleId, subMenuMasterVm.MenuCategoryId))
                    {
                        ModelState.AddModelError("", "SubMenu Already Exists");
                        return(View(subMenuMasterVm));
                    }
                    else
                    {
                        SubMenuMaster subMenuMaster = new SubMenuMaster()
                        {
                            SubMenuId      = subMenuMasterVm.SubMenuId,
                            RoleId         = subMenuMasterVm.RoleId,
                            MenuCategoryId = subMenuMasterVm.MenuCategoryId,
                            MenuId         = subMenuMasterVm.MenuId,
                            Status         = subMenuMasterVm.Status,
                            Area           = subMenuMasterVm.Area,
                            ControllerName = subMenuMasterVm.ControllerName,
                            ActionMethod   = subMenuMasterVm.ActionMethod,
                            SubMenuName    = subMenuMasterVm.SubMenuName,
                            CreatedOn      = DateTime.Now
                        };
                        subMenuMaster.CreatedBy = Convert.ToInt64(HttpContext.Session.Get <string>(AllSessionKeys.UserId));
                        _unitOfWorkEntityFramework.SubMenuMasterCommand.Update(subMenuMaster);
                        _unitOfWorkEntityFramework.Commit();

                        _notificationService.SuccessNotification("Message", "SubMenu was Updated Successfully!");
                    }

                    return(RedirectToAction("Index", "SubMenuMaster"));
                }

                return(View(subMenuMasterVm));
            }
            catch (Exception)
            {
                throw;
            }
        }