public string CheckOut(Reserva res) { string salida = ""; var crudReserva = new ReservaCrudFactory(); var llave = new LlaveQR() { CodigoQR = res.idQR }; try { llave = crudLlaveQR.Retrieve <LlaveQR>(llave); if (llave == null) { // La llave QR no existe throw new BussinessException(20); } var reserva = new Reserva() { Codigo = llave.IdReserva }; res = crudReserva.Retrieve <Reserva>(reserva); llave.EstadoQR = "3"; crudLlaveQR.Update(llave); res.Estado = "0"; crudReserva.Update(res); salida = "Check out realizado con éxito"; } catch (Exception ex) { ExceptionManager.GetInstance().Process(ex); } return(salida); }
public string CheckIn(Reserva res) { string salida = ""; int idHabitacion = res.IdHabitacion; string idHotel = res.IdHotel; int codigoRes = res.Codigo; var crudReserva = new ReservaCrudFactory(); var llave = new LlaveQR() { CodigoQR = res.idQR }; try { llave = crudLlaveQR.Retrieve <LlaveQR>(llave); if (llave == null) { // La llave QR no existe throw new BussinessException(20); } var reserva = new Reserva() { Codigo = llave.IdReserva }; res = crudReserva.Retrieve <Reserva>(reserva); res.IdHabitacion = idHabitacion; if (res.IdHotel.Equals(idHotel) && llave.IdReserva == codigoRes) { switch (llave.EstadoQR) { case "2": // La llave QR se encuentra inactiva throw new BussinessException(57); case "3": // La llave QR ya expiró throw new BussinessException(58); } switch (res.Estado) { case "0": // La reserva ya terminó! throw new BussinessException(18); case "1": salida = "Adelante!"; break; case "2": if (res.FechaInicio.Date.CompareTo(DateTime.Now.Date) <= 0) { salida = "Check in exitoso!"; res.Estado = "1"; crudReserva.Update(res); } else { // La fecha no es válida! throw new BussinessException(19); } break; case "3": // La reserva está cancelada! throw new BussinessException(18); } } else { // El código no pertenece a esta reservación throw new BussinessException(23); } } catch (Exception ex) { ExceptionManager.GetInstance().Process(ex); } return(salida); }
public async Task Create(Reserva reserva) { try { FacturaCrudFactory crudFactura = new FacturaCrudFactory(); LlaveQRManager mngLlave = new LlaveQRManager(); UsuarioManager mngUsuario = new UsuarioManager(); HotelCrudFactory crudHotel = new HotelCrudFactory(); var resReserva = crudReserva.Retrieve <Reserva>(reserva); Factura factura = new Factura(); while (resReserva != null) { var guid = Guid.NewGuid(); var justNumbers = new String(guid.ToString().Where(Char.IsDigit).ToArray()); reserva.Codigo = int.Parse(justNumbers.Substring(0, 9)); resReserva = crudReserva.Retrieve <Reserva>(reserva); } ; var resFactura = new Factura(); do { var guid = Guid.NewGuid(); var justNumbers = new String(guid.ToString().Where(Char.IsDigit).ToArray()); factura.NumFacturacion = int.Parse(justNumbers.Substring(0, 9)); resFactura = crudFactura.Retrieve <Factura>(factura); } while (resFactura != null); int[] cH = reserva.CantHabitaciones; int cont = 0; var r = new Reserva { Codigo = reserva.Codigo, FechaInicio = reserva.FechaInicio, FechaFin = reserva.FechaFin, Precio = reserva.Precio, Promocion = reserva.Promocion, IdUsuario = reserva.IdUsuario, IdHotel = reserva.IdHotel, CantPersonas = reserva.CantPersonas, NumFacturacion = factura.NumFacturacion }; crudReserva.Create(r); cont = 0; foreach (string tipoHab in reserva.TipoHabitaciones) { var r3 = new Reserva { TipoHab = tipoHab, CantHab = cH[cont], Codigo = reserva.Codigo, IdHotel = reserva.IdHotel, FechaInicio = reserva.FechaInicio, FechaFin = reserva.FechaFin }; crudReserva.AsignarHabitacionReserva(r3); cont++; } Usuario usuarioEncontrado = null; var u = new Usuario { Identificacion = reserva.IdUsuario }; usuarioEncontrado = mngUsuario.RetrieveById(u); LlaveQR llave = new LlaveQR(); llave.EstadoQR = "1"; llave.IdReserva = reserva.Codigo; llave.IdUsuario = usuarioEncontrado.Correo; await mngLlave.CreateYEnviar(llave, usuarioEncontrado); var rQR = new LlaveQR { IdReserva = reserva.Codigo }; var respuesta = mngLlave.RetrieveAllByReserva(rQR); var llaveReserva = new Reserva { Codigo = reserva.Codigo, LlaveQR = respuesta[0].ImagenQR }; crudReserva.AsignarQRReservaReserva(llaveReserva); //string numeroFactura, string descripcion, ArrayList detalles, Hotel hotel, Usuario cliente var detalleFactura = new LineaDetalleFactura { Nombre = "Reservación", Precio = (float)reserva.Precio, Cantidad = 1, SubTotal = (float)reserva.Precio, Impuesto = 0, Total = (float)reserva.Precio }; ArrayList detalle = new ArrayList(); detalle.Add(detalleFactura); var h = new Hotel { CedulaJuridica = reserva.IdHotel }; Hotel hotel = crudHotel.Retrieve <Hotel>(h); string numFactura = Convert.ToString(factura.NumFacturacion); await PdfManager.Create(numFactura, "el pago de una reservación en AdTrip", detalle, hotel, (Usuario)usuarioEncontrado); } catch (Exception ex) { ExceptionManager.GetInstance().Process(ex); } }