public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products.OrderByDescending(x => x.AddedDate).Where(x => x.IsDeleted == false || x.IsDeleted == null); DB.Categories category = null; if (id > 0) { products = products.Where(x => x.Category_Id == id); category = context.Categories.FirstOrDefault(x => x.Id == id); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }
public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products; DB.Categories category = null; if (id > 0) { products = products.Where(x => x.Category_Id == id); category = context.Categories.FirstOrDefault(x => x.Id == id); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }
// GET: Product public ActionResult Product(int id = 0) { IQueryable <DB.Products> products = context.Products.Where(x => x.isDeleted == false || x.isDeleted == null); DB.Categories category = null; if (id > 0) { products = products.Where(x => x.Category_Id == id); category = context.Categories.FirstOrDefault(x => x.Id == id); } var viewmodel = new UsKirtasiye.Models.ProductModel() { Products = products.ToList(), Categories = category }; return(View(viewmodel)); }
public ActionResult Edit(DB.Categories category) { var currentuser = (UsKirtasiye.DB.Members)Session["LogonUser"]; if (Session["LogonUser"] == null) { return(RedirectToAction("Index", "Index")); } else if (currentuser.UserGroup != 10) { return(RedirectToAction("Index", "Index")); } else if (category.Id > 0) { var cat = context.Categories.FirstOrDefault(x => x.Id == category.Id); cat.Name = category.Name; cat.ModifedDate = DateTime.Now; cat.IsDeleted = false; if (category.Parent_Id > 0) { cat.Parent_Id = category.Parent_Id; } else { cat.Parent_Id = null; } } else { category.AddedDate = DateTime.Now; category.IsDeleted = false; if (category.Parent_Id == 0) { category.Parent_Id = null; } context.Entry(category).State = System.Data.Entity.EntityState.Added; } context.SaveChanges(); return(RedirectToAction("Category", "Category")); }
public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products.OrderByDescending(x => x.AddedDate).Where(x => x.IsDeleted == false || x.IsDeleted == null); DB.Categories category = null; if (id > 0) { category = context.Categories.FirstOrDefault(x => x.Id == id); var allCategories = GetChildCategories(category); allCategories.Add(category); var catIntList = allCategories.Select(x => x.Id).ToList(); products = products.Where(x => catIntList.Contains(x.Category_Id)); } var viewModel = new Models.i.IndexModel { Products = products.ToList(), Category = category }; return(View(viewModel)); }
public ActionResult Edit(DB.Categories category) { if (IsLogon() == false) { return(RedirectToAction("index", "i")); } if (category.Id > 0) { var cat = context.Categories.FirstOrDefault(x => x.Id == category.Id); cat.Description = category.Description; cat.Name = category.Name; cat.ModifedDate = DateTime.Now; cat.IsDeleted = false; if (category.Parent_Id > 0) { cat.Parent_Id = category.Parent_Id; } else { cat.Parent_Id = null; } } else { category.AddedDate = DateTime.Now; category.IsDeleted = false; if (category.Parent_Id == 0) { category.Parent_Id = null; } context.Entry(category).State = System.Data.Entity.EntityState.Added; } context.SaveChanges(); return(RedirectToAction("i")); }
public ActionResult Edit(DB.Categories category) { //Var olan kategoriyi güncellemek için if (category.Id > 0) { var cat = context.Categories.FirstOrDefault(x => x.Id == category.Id); cat.Description = category.Description; cat.Name = category.Name; cat.ModifedDate = DateTime.Now; cat.isDeleted = false; if (category.Parent_Id > 0) { cat.Parent_Id = category.Parent_Id; } else { cat.Parent_Id = null; } } //Yeni bir kategori eklemek için else { category.AddedDate = DateTime.Now; category.isDeleted = false; if (category.Parent_Id == 0) { category.Parent_Id = null; } context.Entry(category).State = System.Data.Entity.EntityState.Added; } context.SaveChanges(); return(RedirectToAction("Index", "Category")); }