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 void setLineaFactura(ReservaServicio resserv, float precio, DateTime fechaIni, DateTime fechaFin, int numHabitacion) { int idFact; LineaFactura lfact = new LineaFactura(); FacturasController fc = new FacturasController(_context); idFact = fc.getNumeroFactura(numHabitacion, fechaIni, fechaFin); Factura factura = _context.Factura.SingleOrDefault(m => m.idFactura == idFact); lfact.precio = precio; lfact.ReservaServicio = resserv; lfact.Factura = factura; factura.LineasFactura.Add(lfact); _context.Factura.Update(factura); _context.Factura.SingleOrDefault(m => m.idFactura == idFact).LineasFactura.Add(lfact); _context.LineaFactura.Add(lfact); }