public async Task <IActionResult> EditPost(int id, AppointmentDetailViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } Appointments obj = null; if (orm == 1) { obj = qdb.retAppointment(id); } else { obj = await _db.Appointments.FirstAsync(e => e.Id == id); } obj.CustomerName = vm.Appointments.CustomerName; obj.CustomerEmail = vm.Appointments.CustomerEmail; obj.IsConfirmed = vm.Appointments.IsConfirmed; obj.CustomerNumber = vm.Appointments.CustomerNumber; obj.AppointmentDate = vm.Appointments.AppointmentDate.AddHours(vm.Appointments.AppointmentTime.Hour) .AddMinutes(vm.Appointments.AppointmentTime.Minute); if (orm == 1) { qdb.upAppointment(obj); } else { await _db.SaveChangesAsync(); } TempData["edit"] = 1; return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Pay() { var idd = HttpContext.Session.Get <Dictionary <int, int> >("ls")[int.MaxValue]; if (CreditCard.AppointmentId != idd) { return(NotFound()); } if (!ModelState.IsValid) { return(View(CreditCard)); } var id = CreditCard.AppointmentId; CreditCard.Appointments = null; List <ProductsSelectedForAppointment> psd = null; if (orm == 1) { qdb.incredit(CreditCard); psd = qdb.retpsa_with_ai(id); foreach (var item in psd) { var product = qdb.retProduct(item.ProductId); product.Count -= item.Count; if (product.Count == 0) { product.Available = false; } qdb.upProduct(product); } var appointment = qdb.retAppointment(id); appointment.IsConfirmed = true; qdb.upAppointment(appointment); } else { _db.CreditCards.Add(CreditCard); await _db.SaveChangesAsync(); psd = await _db.ProductsSelectedForAppointments.Where(e => e.AppointmentId == id) .ToListAsync(); foreach (var item in psd) { var product = _db.Products.First(e => e.Id == item.ProductId); product.Count -= item.Count; if (product.Count == 0) { product.Available = false; } } _db.Appointments.First(e => e.Id == id).IsConfirmed = true; await _db.SaveChangesAsync(); } Dictionary <int, int> dic = new Dictionary <int, int>(); HttpContext.Session.Set("ls", dic); TempData["congrats"] = 1; return(RedirectToAction("Index", "Home")); }