public async Task <IActionResult> Index() { if (Convert.ToInt32(TempData["edit"]) == 1) { ViewBag.edit = true; } else if (Convert.ToInt32(TempData["delete"]) == 1) { ViewBag.delete = true; } else if (Convert.ToInt32(TempData["create"]) == 1) { ViewBag.create = true; } List <Products> product; if (orm == 1) { product = qdb.retProduct(); qdb.include_pt_st(product); } else { product = await _db.Products.Include(m => m.SpecialTags).Include(m => m.ProductTypes).ToListAsync(); } return(View(product)); }
public IActionResult Index() { Dictionary <int, int> lst = HttpContext.Session.Get <Dictionary <int, int> >("ls"); if (lst != null && lst.TryGetValue(int.MinValue, out int v) && v == 1) { HttpContext.Session.Set("ls", new Dictionary <int, int>()); lst = new Dictionary <int, int>(); } if (lst != null) { if (orm == 1) { List <Products> ls = new List <Products>(); foreach (int i in lst.Keys) { Products p = qdb.retProduct(i); ls.Add(p); qdb.include_pt_st(ls); p.Price = lst[i] * p.Price; ShoppingCardvm.Products.Add(p); ls.Clear(); } } else { foreach (int i in lst.Keys) { Products p = _db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags) .FirstOrDefault(e => e.Id == i); if (p != null) { p.Price = lst[i] * p.Price; } ShoppingCardvm.Products.Add(p); } } //foreach (int i in lst.Keys) //{ // Products p = _db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags) // .FirstOrDefault(e => e.Id == i); // p.Price = lst[i] * p.Price; // ShoppingCardvm.Products.Add(p); //} } return(View(ShoppingCardvm)); }
// Get : Edit public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } List <Products> products = null; Appointments appointments = null; if (orm == 1) { products = qdb.p_join_psa((int)id); qdb.include_pt_st(products); appointments = qdb.retAppointment((int)id); } else { products = (from i in _db.Products join j in _db.ProductsSelectedForAppointments on i.Id equals j.ProductId where j.AppointmentId == id select i ).Include(e => e.ProductTypes).ToList(); appointments = (from i in _db.Appointments where i.Id == (int)id select i).FirstOrDefault(); } //var appointment = (from i in _db.Appointments where i.Id == (int) id select i).FirstOrDefault(); var applicationUsers = (from i in _db.ApplicationUsers select i).ToList(); AppointmentDetailViewModel avm = new AppointmentDetailViewModel() { Appointments = appointments, ApplicationUsers = applicationUsers, Products = products }; return(View(avm)); }
//[BindProperty] //public bool Error { get; set; } public IActionResult Index(ProductViewModelForList vm) { if (vm.tag == "All") { vm.tag = null; TempData["tag"] = null; } if (vm.type == "All") { vm.type = null; TempData["type"] = null; } if (TempData["tag"] != null) { vm.tag = TempData["tag"].ToString(); TempData.Keep(); } else { if (vm.tag != null) { TempData["tag"] = vm.tag; TempData.Keep(); } } if (TempData["type"] != null) { vm.type = TempData["type"].ToString(); TempData.Keep(); } else { if (vm.type != null) { TempData["type"] = vm.type; TempData.Keep(); } } //ProductViewModelForList vm = new ProductViewModelForList(); //vm.tag = tag; //vm.type = type; if (TempData["congrats"] != null && Convert.ToInt32(TempData["congrats"]) == 1) { ViewBag.congrats = true; TempData["congrats"] = null; } if (TempData["orm"] != null) { int o = Convert.ToInt32(TempData["orm"]); if (o == 1) { ViewBag.orm = 0; } else { ViewBag.orm = 0; } } bool tagg = true, typee = true; if (vm.tag == null) { tagg = false; } if (vm.type == null) { typee = false; } List <Products> temp = null; if (orm == 1) { temp = qdb.retProduct(); qdb.include_pt_st(temp); } else { temp = _db.Products.Include(e => e.SpecialTags).Include(e => e.ProductTypes).ToList(); } if (tagg) { temp = temp.Where(e => e.SpecialTags.Name == vm.tag).ToList(); } if (typee) { temp = temp.Where(e => e.ProductTypes.Name == vm.type).ToList(); } vm.Products = temp; vm.SpecialTags = _db.SpecialTags.ToList(); vm.ProductTypes = _db.ProductTypes.ToList(); return(View(vm)); }