public async Task <IActionResult> AppointmentConfirmation(int id) { List <ProductsSelectedForAppointment> lst = null; if (orm == 1) { ShoppingCardvm.Appointments = qdb.retAppointment(id); lst = qdb.retpsaall(); } else { ShoppingCardvm.Appointments = await _db.Appointments.FirstOrDefaultAsync(e => e.Id == id); lst = await _db.ProductsSelectedForAppointments.ToListAsync(); } Dictionary <int, int> ls = HttpContext.Session.Get <Dictionary <int, int> >("ls"); if (ls[int.MaxValue] != ShoppingCardvm.Appointments.Id) { return(NotFound()); } lst = lst.Where(e => e.AppointmentId == id).ToList(); if (orm == 1) { foreach (ProductsSelectedForAppointment psa in lst) { Products p = qdb.retProduct(psa.ProductId); List <Products> products = new List <Products>(); products.Add(p); qdb.include_pt_st(products); ShoppingCardvm.Products.Add(p); } } else { foreach (ProductsSelectedForAppointment psa in lst) { ShoppingCardvm.Products.Add(_db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags) .FirstOrDefault(e => e.Id == psa.ProductId)); } } //foreach (ProductsSelectedForAppointment psa in lst) //{ // ShoppingCardvm.Products.Add(_db.Products.Include(e => e.ProductTypes).Include(e => e.SpecialTags) // .FirstOrDefault(e => e.Id == psa.ProductId)); //} ls[int.MinValue] = 1; HttpContext.Session.Set("ls", ls); return(View(ShoppingCardvm)); }
public async Task <IActionResult> Index(int appointmentId) { CreditCard.AppointmentId = appointmentId; var idd = HttpContext.Session.Get <Dictionary <int, int> >("ls")[int.MaxValue]; if (CreditCard.AppointmentId != idd) { return(NotFound()); } List <ProductsSelectedForAppointment> psd = new List <ProductsSelectedForAppointment>(); if (orm == 1) { CreditCard.Appointments = qdb.retAppointment(appointmentId); psd = qdb.retpsa_with_ai(appointmentId); foreach (ProductsSelectedForAppointment i in psd) { qdb.include_pi_ai(i); } } else { CreditCard.Appointments = await _db.Appointments.FirstAsync(i => i.Id == appointmentId); psd = _db.ProductsSelectedForAppointments.Where(e => e.AppointmentId == appointmentId).Include(e => e.Products).ToList(); } double price = 0; foreach (ProductsSelectedForAppointment i in psd) { price += i.Products.Price * i.Count; } CreditCard.SalePrice = Convert.ToDecimal(price); return(View(CreditCard)); }
public async Task <IActionResult> Index(string searchName = null, string searchEmail = null, string searchPhone = null, string searchDate = null) { 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; } var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); AppointmentViewModel appointmentVm = new AppointmentViewModel() { Appointments = new List <Appointments>() }; if (orm == 1) { appointmentVm.Appointments = qdb.retAppointment(); } else { appointmentVm.Appointments = await _db.Appointments.Where(e => e.IsConfirmed == false).ToListAsync(); } if (searchName != null) { appointmentVm.Appointments = appointmentVm.Appointments .Where(e => e.CustomerName.ToLower().Contains(searchName.ToLower())).ToList(); } if (searchEmail != null) { appointmentVm.Appointments = appointmentVm.Appointments .Where(e => e.CustomerEmail.ToLower().Contains(searchEmail.ToLower())).ToList(); } if (searchPhone != null) { appointmentVm.Appointments = appointmentVm.Appointments .Where(e => e.CustomerNumber.ToLower().Contains(searchPhone.ToLower())).ToList(); } if (searchDate != null) { try { DateTime date = Convert.ToDateTime(searchDate); appointmentVm.Appointments = appointmentVm.Appointments .Where(e => e.AppointmentDate.ToShortDateString().Equals(date.ToShortDateString())).ToList(); } catch (Exception e) { } } return(View(appointmentVm)); }