public ActionResult CategoryAuthority(int ID) { var user = db.dt_user.FirstOrDefault(); if (Session["personel_id"] == null) return RedirectToAction("Default", "Home"); else { int personel_id = Convert.ToInt32(Session["personel_id"]); user = db.dt_user.Where(a => a.state == 1 && a.ID == personel_id).FirstOrDefault(); if (user == null) return RedirectToAction("Default", "Home"); if (user.unvan_id != 2) { TempData["mesaj"] = "Bu işlemi gerçekleştirmeye yetkiniz yok...!"; return RedirectToAction("CategoryShow"); } List<SelectListItem> listtype = GetTypeList(0); List<SelectListItem> rol = new SelectList(db.dt_rol.Where(a => a.state == 1), "ID", "rolName").ToList<SelectListItem>(); ViewBag.type_id = listtype; ViewBag.RolUser_id = rol; ViewBag.categoryID = ID; ViewBag.userName = user.name + " " + user.surname; int rol_id = Convert.ToInt32(rol.FirstOrDefault().Value); List<userAuthority> FileRol = (from a in db.lu_fileRol where a.rol_id == rol_id && a.category_id == ID select new userAuthority { ID = a.ID, AuthorityName = (from x in db.dt_rol where x.ID == a.rol_id select x.rolName).FirstOrDefault(), FileRead = (a.formRead == false ? "Yok" : "Var"), FileWritre = (a.formWrite == false ? "Yok" : "Var"), erroID = ID }).ToList<userAuthority>(); return View(FileRol); } }
/// <summary> /// fill in dropdown needed values. from category - parent category - root category /// all products must have 3-level category!!! /// </summary> /// <param name="product"></param> private void SetSelectedValues(Product product) { if (product.Pr_Cat_Id < 0) { // if change getRootCategories mapping, then should change binding in viewbag ViewBag.CategoriesL1 = new SelectList(ProductManager.GetRootCategories(), "Cat_id", "Cat_Name"); ViewBag.CategoriesL2 = new SelectList(new List<Category>()); ViewBag.CategoriesL3 = ViewBag.CategoriesL2; return; } // get list of categories from product category Category current = ProductManager.GetCategoryByProductId(product.Pr_Cat_Id); var l3 = ProductManager.GetListOfCategotiesWithSameRootAsParent(current); Category parent = ProductManager.GetParentCategory(current); // get list of categories of parent category var l2 = ProductManager.GetCategoriesByLevel(parent); // get root category list var l1 = ProductManager.GetRootCategories(); Category root = ProductManager.GetParentCategory(parent); // set selected category to dropdown list var level1 = new SelectList(l1, "Cat_id", "Cat_Name"); var selected1 = level1.FirstOrDefault(x => root != null && x.Value == root.Cat_Id.ToString()); if (selected1 != null) { level1 = new SelectList(l1, "Cat_id", "Cat_Name", selectedValue: selected1.Value); } var level2 = new SelectList(l2, "Cat_id", "Cat_Name"); var selected2 = level2.FirstOrDefault(x => parent != null && x.Value == parent.Cat_Id.ToString()); if (selected2 != null) { level2 = new SelectList(l2, "Cat_id", "Cat_Name", selectedValue: selected2.Value); } var level3 = new SelectList(l3, "Cat_id", "Cat_Name"); var selected3 = level3.FirstOrDefault(x => current != null && x.Value == current.Cat_Id.ToString()); if (selected3 != null) { level3 = new SelectList(l3, "Cat_id", "Cat_Name", selected3.Value); } ViewBag.CategoriesL1 = level1; ViewBag.CategoriesL2 = level2; ViewBag.CategoriesL3 = level3; }
public ActionResult EditRotating(int id) { BuffetRotatingWeek week = _dbContext.BuffetRotatingWeeks.First(bi => bi.Id == id); SelectList meatItems = new SelectList(_dbContext.BuffetSchedules.Include("BuffetItem").Where(bi => bi.FoodType.Name == "Buffet Meat"), "Id", "BuffetItem.Name"); var meat = meatItems.FirstOrDefault(m => m.Value == week.Meat.Id.ToString()); if (meat != null) { meat.Selected = true; } ViewBag.MeatItems = meatItems; SelectList casseroleItems = new SelectList(_dbContext.BuffetSchedules.Include("BuffetItem").Where(bi => bi.FoodType.Name == "Casserole"), "Id", "BuffetItem"); var casserole = casseroleItems.FirstOrDefault(c => c.Value == week.Casserole.Id.ToString()); if (casserole != null) { casserole.Selected = true; } ViewBag.CasseroleItems = casseroleItems; SelectList cornItems = new SelectList(_dbContext.BuffetSchedules.Include("BuffetItem").Where(bi => bi.FoodType.Name == "Corn"), "Id", "BuffetItem"); var corn = cornItems.FirstOrDefault(c => c.Value == week.Corn.Id.ToString()); if (corn != null) { corn.Selected = true; } ViewBag.CornItems = cornItems; SelectList beanItems = new SelectList(_dbContext.BuffetSchedules.Include("BuffetItem").Where(bi => bi.FoodType.Name == "Beans"), "Id", "BuffetItem"); var beans = beanItems.FirstOrDefault(c => c.Value == week.Beans.Id.ToString()); if (beans != null) { beans.Selected = true; } ViewBag.BeanItems = beanItems; return View(week); }
public static IEnumerable<SelectListItem> GetOrderedListOfDomainsWithGroupId(ProfileMembers domains, SelectListItem defaultProfile, ProfileRepository profileRepository) { if (defaultProfile != null) domains.Profile = GetProfile(defaultProfile.Value, 0, -1, profileRepository); var listOfDomains = new SelectList(domains.Profile.GroupingMetadatas.OrderBy(g => g.Sequence), "GroupId", "GroupName"); var selectedDomain = new SelectList(listOfDomains, "Value", "Key", listOfDomains.FirstOrDefault().Value).SelectedValue.ToString(); return listOfDomains.Select(x => new SelectListItem { Selected = (x.Value == selectedDomain), Text = x.Text, Value = x.Value }); ; }