public async Task <IActionResult> SeleccionComensales(int nComensales, int nHabitacion, int idServicio, string nCliente) { ReservaMenuViewModel rmvm = new ReservaMenuViewModel { nHabitacion = nHabitacion, idServicio = idServicio, nCliente = nCliente }; Menu menu = _context.Menu.FirstOrDefault(m => m.idServicio == idServicio); Habitacion habitacion = await _context.Habitacion.SingleOrDefaultAsync <Habitacion>(h => h.numero == nHabitacion); string result = "Failure"; ResultMenuViewModel remvm = new ResultMenuViewModel { menu = menu, result = result }; if (menu == null || habitacion == null) { return(RedirectToAction("ContratarMenu", remvm)); } if (nComensales <= 0) { return(View("SeleccionComensales", rmvm)); } FacturasController fc = new FacturasController(_context); ReservaHabitacionsController rhc = new ReservaHabitacionsController(_context); Reserva reserva = await rhc.GetReserva(nHabitacion); Factura factura = await fc.GetFactura(reserva); LineaFacturasController lfc = new LineaFacturasController(_context); result = "Error: couldn't get factura"; if (factura != null) { bool chk = await lfc.CrearLineaMenu(menu, nComensales, factura, habitacion); if (!chk) { result = "Error: out of time"; } else { result = "Success"; } } remvm.result = result; return(RedirectToAction("ContratarMenu", remvm)); }
public async Task <IActionResult> ContratarMenu(int menuId, int nHabitacion, int menuIdOld, int nHabitacionOld) { Menu menu = _context.Menu.FirstOrDefault(m => m.idServicio == menuId); ResultMenuViewModel remvm = new ResultMenuViewModel { menu = menu }; int regimen = GetRegimen(menu); if (regimen == Regimen.INVALIDO) { ViewBag.Menus = new SelectList(_context.Menu, "idServicio", "nombre", remvm.menu); remvm.result = "Error: Invalid menu"; ViewData["menuId"] = 0; return(View("ContratarMenu", remvm)); } DateTime hora = SystemTime.Now(); if (menu.horaFin.TimeOfDay.CompareTo(hora.TimeOfDay) < 0 || menu.horaInicio.TimeOfDay.CompareTo(hora.TimeOfDay) > 0) { ViewBag.Menus = new SelectList(_context.Menu, "idServicio", "nombre", remvm.menu); remvm.result = "Error: Out of time"; ViewData["menuId"] = 0; return(View("ContratarMenu", remvm)); } ReservasController rc = new ReservasController(_context); ReservaHabitacionsController rhc = new ReservaHabitacionsController(_context); Reserva r = await rhc.GetReserva(nHabitacion); bool paid = rc.ComidaIncluida(r, regimen); if (r == null) { remvm.result = "Error: Reserva not found"; ViewBag.Menus = new SelectList(_context.Menu, "idServicio", "nombre", remvm.menu); ViewData["menuId"] = 0; return(View("ContratarMenu", remvm)); } String nCliente = r.Cliente.nombre + " " + r.Cliente.apellidos; if (menuId != menuIdOld || nHabitacion != nHabitacionOld) { remvm.result = "Cliente: " + nCliente + '\n' + "Pulse de nuevo contratar para confirmar."; ViewData["menuId"] = menuId; ViewData["nHabitacion"] = nHabitacion; ViewData["nCliente"] = nCliente; ViewBag.Menus = new SelectList(_context.Menu, "idServicio", "nombre", remvm.menu); return(View("ContratarMenu", remvm)); } if (paid) { remvm.result = "Success"; ViewBag.Menus = new SelectList(_context.Menu, "idServicio", "nombre", remvm.menu); ViewData["menuId"] = 0; return(View("ContratarMenu", remvm)); } ReservaMenuViewModel rmvm = new ReservaMenuViewModel(); rmvm.nHabitacion = nHabitacion; rmvm.idServicio = menu.idServicio; rmvm.nCliente = nCliente; return(RedirectToAction("SeleccionComensales", rmvm)); }