public ActionResult CreateMenus(sidebar_menus menus, HttpPostedFileBase imageFile, string MenuStyle, int DashboardAccess = 0, int SidebarAccess = 0, int roleid = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } string imageUrl = "", imageUrl1 = ""; if (imageFile != null) { int imageSize = imageFile.ContentLength; if ((imageSize / 1024 / 1024) < 1) { string fileExtension = Path.GetExtension(imageFile.FileName); string imgName = imageFile.FileName; string[] imgSplit = imgName.Split('.'); Image img = Image.FromStream(imageFile.InputStream, true, true); if (DashboardAccess == 1) { Image imgSave = ReduceImageSize(img, "DashImage", null); string imgUrl = SaveImage(imgSave, imageFile.FileName, "DashImage", null); imageUrl = "/images/" + imageFile.FileName; } if (SidebarAccess == 1) { Image imgSave1 = ReduceImageSize(img, null, "SideImage"); string imgUrl1 = SaveImage(imgSave1, imgSplit[0], null, "SideImage", fileExtension); imageUrl1 = "/images/" + imgSplit[0] + "(1)" + fileExtension; } } else { ViewBag.DisplayOrder = new SelectList(db.menus.Where(m => m.IsDeleted == 0).OrderBy(m => m.DisplayOrder), "DisplayOrder", "DisplayOrder"); ViewData["MenuStyle"] = new SelectList(db.dashboard_menus.Where(m => m.IsDeleted == 0 && m.ColourDiv != null), "Id", "ColourDiv", MenuStyle).ToList(); TempData["toaster_warning"] = "Image Size is larger"; return(View()); } } var value = db.menus.Where(m => m.DisplayOrder == menus.DisplayOrder).Select(m => m.DisplayOrder).FirstOrDefault(); if (value != null) { int displayOrder = Convert.ToInt32(value); var menuList = db.menus.Where(m => m.IsDeleted == 0 && m.DisplayOrder >= displayOrder).ToList(); foreach (var item in menuList) { item.DisplayOrder = item.DisplayOrder + 1; db.SaveChanges(); } } menu menu = new menu(); menu.MenuName = menus.MenuName; menu.IsDeleted = 0; menu.IsDashboard = DashboardAccess; menu.IsSideMenubar = SidebarAccess; menu.DisplayOrder = menus.DisplayOrder; db.menus.Add(menu); db.SaveChanges(); var menuId = db.menus.Where(m => m.MenuName == menus.MenuName).Select(m => m.Id).FirstOrDefault(); if (SidebarAccess == 1) { sidebar_menus sidebarMenus = new sidebar_menus(); sidebarMenus.MenuName = menus.MenuName; sidebarMenus.MenuId = menuId; sidebarMenus.MenuURL = menus.MenuURL; if (imageUrl1 != "") { sidebarMenus.ImageURL = imageUrl1; } sidebarMenus.IsDeleted = 0; db.sidebar_menus.Add(sidebarMenus); db.SaveChanges(); } if (DashboardAccess == 1) { dashboard_menus dashboardMenus = new dashboard_menus(); dashboardMenus.MenuName = menus.MenuName; dashboardMenus.MenuUrl = menus.MenuURL; dashboardMenus.MenuId = menuId; dashboardMenus.ColourDiv = MenuStyle; if (imageUrl != "") { dashboardMenus.ImageUrl = imageUrl; } dashboardMenus.IsDeleted = 0; db.dashboard_menus.Add(dashboardMenus); db.SaveChanges(); } //date: 25-8-2020 (issue in side bar menu not displaying newly created menu item) int roleId = Convert.ToInt32(Session["RoleID"]); user_menus userval = new user_menus(); userval.MenuId = menuId; userval.RoleId = roleid; userval.MenuStatus = true; userval.IsDeleted = 0; db.user_menus.Add(userval); db.SaveChanges(); TempData["toaster_success"] = "Menu Added Successfully"; return(RedirectToAction("MenusList")); }
public string UpdateMenus(int roleId, string menuIds, string unMenuIds) { string res = ""; if (menuIds != null) { menuIds = menuIds.Replace("[", ""); menuIds = menuIds.Replace("]", ""); menuIds = menuIds.Replace("\"", ""); string[] menus = menuIds.Split(','); if (!menus.Contains("")) { foreach (var item in menus) { int menuId = Convert.ToInt32(item); var userMenu = db.user_menus.Where(m => m.IsDeleted == 0 && m.RoleId == roleId && m.MenuId == menuId).FirstOrDefault(); if (userMenu == null) { user_menus userMenus = new user_menus(); userMenus.RoleId = roleId; userMenus.MenuId = menuId; userMenus.MenuStatus = true; userMenus.IsDeleted = 0; db.user_menus.Add(userMenus); db.SaveChanges(); TempData["toaster_success"] = "Menu Items Added Successfully"; } else { userMenu.MenuStatus = true; db.SaveChanges(); TempData["toaster_success"] = "Menu Items Updated Successfully"; } } } } if (unMenuIds != null) { unMenuIds = unMenuIds.Replace("[", ""); unMenuIds = unMenuIds.Replace("]", ""); unMenuIds = unMenuIds.Replace("\"", ""); string[] unMenus = unMenuIds.Split(','); if (!unMenus.Contains("")) { foreach (var item in unMenus) { int unMenuId = Convert.ToInt32(item); var userMenu = db.user_menus.Where(m => m.IsDeleted == 0 && m.RoleId == roleId && m.MenuId == unMenuId).FirstOrDefault(); userMenu.MenuStatus = false; db.SaveChanges(); TempData["toaster_success"] = "Menu Items Updated Successfully"; } } } return(res); }