Exemplo n.º 1
0
        public async Task <ActionResult <Reservaciones> > Buscar(int id)
        {
            Reservaciones reservaciones = new Reservaciones();

            try
            {
                var encontrado = await contexto.Reservaciones.Where(r => r.ReservacionId == id).Include(r => r.ReservacionDetalle).FirstOrDefaultAsync();

                if (encontrado == null)
                {
                    return(new Reservaciones());
                }
                if (encontrado.Accesibilidad == false)
                {
                    return(new Reservaciones());
                }
                else
                {
                    reservaciones = encontrado;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(reservaciones);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Inicio,Fin,SalaId,UserId,FechaReservacion")] Reservaciones reservaciones)
        {
            if (ModelState.IsValid)
            {
                Reservaciones reservacion = new Reservaciones();
                HttpClient    client      = new HttpClient();
                StringContent content     = new StringContent(JsonConvert.SerializeObject(reservaciones), Encoding.UTF8, "application/json");

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetTokenRequest());
                client.BaseAddress = new Uri("https://localhost:44312/api/Reservaciones/CrearReservacion");

                var responseTask = client.PostAsync(client.BaseAddress.AbsoluteUri, content);
                responseTask.Wait();
                var result = responseTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsStringAsync();
                    readTask.Wait();

                    reservacion = JsonConvert.DeserializeObject <Reservaciones>(readTask.Result);
                    return(RedirectToAction("Index", "Reservaciones"));
                }
                else
                {
                    var response = result.Content.ReadAsStringAsync();
                    ModelState.AddModelError(result.StatusCode.ToString(), response.Result);
                }
            }
            ViewData["SalaId"] = new SelectList(GetListaSalas(), "Id", "Nombre", reservaciones.SalaId);

            return(View(reservaciones));
        }
Exemplo n.º 3
0
        public ActionResult <Reservaciones> CrearReservacion([FromBody] Reservaciones reservacion)
        {
            TokenManipulations _token = new TokenManipulations(Request);

            reservacion.UserId           = _token.GetLoggedUser();
            reservacion.FechaReservacion = DateTime.Now;
            bool disponible = _reservaciones.EsDiponible(reservacion);

            if (!disponible)
            {
                ModelState.AddModelError("NoDisponible", "Sala no disponible en este horario");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    return(Ok(_reservaciones.CrearReservacion(reservacion)));
                }
                catch (Exception ex)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 4
0
 public void Crear_Reservacion_Campos_Llenos()
 {
     Reservaciones ObjReservaciones = new Reservaciones
     {
     };
     //var
 }
Exemplo n.º 5
0
        public Boolean AgregarReservacion(string vCorreo, string vCedulReservacion, int vEvento)
        {
            if (ComprobarCantidadReservaciones(vCorreo, vEvento))
            {
                if (!ComprobarHora(vEvento))
                {
                    return(false);
                }
                else
                {
                    try
                    {
                        Reservaciones reservaciones = new Reservaciones();
                        reservaciones.CedulaReservacion = vCedulReservacion;
                        reservaciones.IdCliente         = BuscarCliente(vCorreo);
                        reservaciones.IdEvento          = vEvento;
                        contexto.Reservaciones.Add(reservaciones);
                        contexto.SaveChanges();

                        return(true);
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
        public async Task <IActionResult> Put(int Id_Reserva, Reservaciones reservacionDto)
        {
            reservacionDto.IdReserva = Id_Reserva;
            var result = await _repository.UpdateReservacion(reservacionDto);

            return(Ok(result));
        }
Exemplo n.º 7
0
        private Reservaciones GetReservacion(int id)
        {
            Reservaciones reservacion = new Reservaciones();
            HttpClient    client      = new HttpClient();

            //dejo hardcode el token del admin para realizar pruebas mas rapido.
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetTokenRequest());
            client.BaseAddress = new Uri("https://localhost:44312/api/Reservaciones/GetReservacion?id=" + id);
            var responseTask = client.GetAsync(client.BaseAddress);

            responseTask.Wait();

            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var readTask = result.Content.ReadAsStringAsync();
                readTask.Wait();

                reservacion = JsonConvert.DeserializeObject <Reservaciones>(readTask.Result);
            }
            else
            {
                return(null);
            }
            return(reservacion);
        }
Exemplo n.º 8
0
 public List <Reservaciones> BuscaReservacionDatos(String dato)
 {
     try
     {
         SqlConnection cnx = cn.conectar();
         cm = new SqlCommand("nuevaReservacion", cnx);
         cm.Parameters.AddWithValue("@b", 6);
         cm.Parameters.AddWithValue("@Id", "");
         cm.Parameters.AddWithValue("@Fecha", dato);
         cm.Parameters.AddWithValue("Tiempo", dato);
         cm.Parameters.AddWithValue("@NumeroCliente", dato);
         cm.Parameters.AddWithValue("@Numero", dato);
         cm.CommandType = CommandType.StoredProcedure;
         cnx.Open();
         dr = cm.ExecuteReader();
         listaReservacion = new List <Reservaciones>();
         while (dr.Read())
         {
             Reservaciones r = new Reservaciones();
             r.Id            = Convert.ToInt32(dr["Id"].ToString());
             r.Fecha         = dr["Fecha"].ToString();
             r.Tiempo        = dr["Tiempo"].ToString();
             r.NumeroCliente = dr["@NumeroCliente"].ToString();
             r.Numero        = dr["@Numero"].ToString();
             listaReservacion.Add(r);
         }
     }
     catch (Exception e)
     {
         e.Message.ToString();
         listaReservacion = null;
     }
     finally { cm.Connection.Close(); }
     return(listaReservacion);
 }
Exemplo n.º 9
0
        public int EditarReservacion(Reservaciones re)
        {
            try
            {
                SqlConnection cnx = cn.conectar();

                cm = new SqlCommand("nuevaReservacion", cnx);
                cm.Parameters.AddWithValue("@b", 3);
                cm.Parameters.AddWithValue("@Id", "");
                cm.Parameters.AddWithValue("@Fecha", re.Fecha);
                cm.Parameters.AddWithValue("Tiempo", re.Tiempo);
                cm.Parameters.AddWithValue("@NumeroCliente", re.NumeroCliente);
                cm.Parameters.AddWithValue("@Numero", re.Numero);


                cm.CommandType = CommandType.StoredProcedure;
                cnx.Open();
                cm.ExecuteNonQuery();
                indicador = 1;
            }
            catch (Exception e)
            {
                e.Message.ToString();
                indicador = 0;
            }
            finally { cm.Connection.Close(); }
            return(indicador);
        }
Exemplo n.º 10
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnGuardar.Text == "Guardar")
                {
                    Reservaciones objReservaciones = new Reservaciones();
                    objReservaciones.Fecha         = txtFecha.Text;
                    objReservaciones.Tiempo        = txtTiempo.Text;
                    objReservaciones.NumeroCliente = txtNumeroCliente.Text;
                    objReservaciones.Numero        = txtNumero.Text;

                    if (lN.insertarReservacion(objReservaciones) > 0)
                    {
                        MessageBox.Show("Agregado con éxito!");
                        dgvReservaciones.DataSource = lN.ListaReservacion();
                        txtFecha.Text                = "";
                        txtTiempo.Text               = "";
                        txtNumeroCliente.Text        = "";
                        txtNumero.Text               = "";
                        tabReservaciones.SelectedTab = tabPage2;
                    }
                    else
                    {
                        MessageBox.Show("Error al agregar Reservacion");
                    }
                }

                if (btnGuardar.Text == "Actualizar")
                {
                    Reservaciones objReservaciones = new Reservaciones();
                    objReservaciones.Fecha         = txtFecha.Text;
                    objReservaciones.Tiempo        = txtTiempo.Text;
                    objReservaciones.NumeroCliente = txtNumeroCliente.Text;
                    objReservaciones.Numero        = txtNumero.Text;

                    if (lN.EditarReservacion(objReservaciones) > 0)
                    {
                        MessageBox.Show("Actualizado con éxito!");
                        txtFecha.Text                = "";
                        txtTiempo.Text               = "";
                        txtNumeroCliente.Text        = "";
                        txtNumero.Text               = "";
                        tabReservaciones.SelectedTab = tabPage2;
                    }

                    else
                    {
                        MessageBox.Show("Error al actualizar Reservacion");
                    }

                    btnGuardar.Text = "Guardar";
                }
            }
            catch
            {
                MessageBox.Show("Errorrrr");
            }
        }
Exemplo n.º 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            Reservaciones reservaciones = db.Reservaciones.Find(id);

            db.Reservaciones.Remove(reservaciones);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public Reservaciones GetReservacion(int id)
        {
            Reservaciones rese = _dbContext.Reservaciones.Include(x => x.Sala).Include(x => x.Usuario).First(x => x.Id == id);

            rese.Sala.Reservaciones    = null;
            rese.Usuario.Reservaciones = null;
            return(rese);
        }
Exemplo n.º 13
0
        public Reservaciones DataReserva3()
        {
            Reservaciones reserva = new Reservaciones();

            reserva.horaInicial = new DateTime(10);
            reserva.horaFinal   = new DateTime(15);

            return(reserva);
        }
Exemplo n.º 14
0
        public Boolean EliminarReservacion(int id)
        {
            Reservaciones reservaciones = (from r in contexto.Reservaciones
                                           where r.IdReservacion == id
                                           select r).FirstOrDefault();

            contexto.Reservaciones.Remove(reservaciones);
            contexto.SaveChanges();
            return(true);
        }
Exemplo n.º 15
0
        public Reservaciones CrearReservacion(Reservaciones reservacion)
        {
            if (reservacion.Fin <= reservacion.Inicio)
            {
                throw new Exception("La fecha de finalizacion no puede ser menor o igual a la de inicio");
            }

            _dbContext.Reservaciones.Add(reservacion);
            _dbContext.SaveChanges();
            return(reservacion);
        }
Exemplo n.º 16
0
        public Reservaciones DataReserva1()
        {
            Reservaciones reserva = new Reservaciones();

            reserva.userId      = "";
            reserva.idCancha    = 0;
            reserva.horaInicial = new DateTime(10);
            reserva.horaFinal   = new DateTime(11);

            return(reserva);
        }
Exemplo n.º 17
0
 public async Task <ActionResult <bool> > Guardar(Reservaciones reservaciones)
 {
     if (Existe(reservaciones.ReservacionId))
     {
         return(await Modificar(reservaciones));
     }
     else
     {
         return(await Insertar(reservaciones));
     }
 }
Exemplo n.º 18
0
        public Reservaciones DataReserva5()
        {
            Reservaciones reserva = new Reservaciones();

            reserva.idCancha    = 2;
            reserva.userId      = "bkbxhdr";
            reserva.horaInicial = new DateTime().AddHours(10);
            reserva.horaFinal   = new DateTime().AddHours(15);

            return(reserva);
        }
        public async Task <ActionResult> putReservacion(int idReservacion, Reservaciones reservacion)
        {
            if (idReservacion == reservacion.idReservacion)
            {
                _db.Entry(reservacion).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return(Ok());
            }

            return(BadRequest());
        }
Exemplo n.º 20
0
        protected void GuardarButton_Click(object sender, EventArgs e)
        {
            Reservaciones ReservacionDetalle;

            if (Session["ReservacionSession"] == null)
            {
                Session["ReservacionSession"] = new Reservaciones();
            }

            ReservacionDetalle = (Reservaciones)Session["ReservacionSession"];

            if (ReservacionIdTextBox.Text.Length > 0)
            {
                if (LLenarDatos())
                {
                    Reservacion.ReservacionId = Seguridad.ValidarEntero(ReservacionIdTextBox.Text);

                    if (Reservacion.Editar())
                    {
                        Mensajes.ShowToastr(this.Page, "Se Modifico", "Informacion", "Success");
                        Limpiar();
                    }
                    else
                    {
                        Mensajes.ShowToastr(this.Page, "No Se Modifico", "Error", "Error");
                    }
                }
                else
                {
                    Mensajes.ShowToastr(this.Page, "Faltan Datos", "Error", "Error");
                }
            }
            else
            {
                if (LLenarDatos())
                {
                    if (Reservacion.Insertar())
                    {
                        Mensajes.ShowToastr(this.Page, "Se Registro", "Felicidades", "Success");
                        Limpiar();
                    }
                    else
                    {
                        Mensajes.ShowToastr(this.Page, "No se pudo Registrar", "Error", "Error");
                    }
                }
                else
                {
                    Mensajes.ShowToastr(this.Page, "Faltan Datos", "Error", "Error");
                }
            }
        }
        private void BtnReservaciones_Click(object sender, EventArgs e)
        {
            if (splitContainer1.Panel2.Controls.Count > 0)
            {
                splitContainer1.Panel2.Controls.Clear();
            }
            Reservaciones reservaciones = new Reservaciones(controladorCliente);

            reservaciones.TopLevel = false;
            reservaciones.Dock     = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(reservaciones);
            reservaciones.Show();
        }
Exemplo n.º 22
0
        private async Task OcuparHabitacion(Reservaciones reservacion)
        {
            bool       guardar;
            Habitacion habitacion = new Habitacion();

            foreach (var item in reservacion.ReservacionDetalle)
            {
                habitacion        = contexto.Habitacion.Where(h => h.NumeroHabitacion == item.NumeroHabitacion).FirstOrDefault();
                habitacion.Estado = false;
                contexto.Entry(habitacion).State = EntityState.Modified;
                guardar = await contexto.SaveChangesAsync() > 0;
            }
        }
        public async Task <ActionResult <Reservaciones> > postReservacion(Reservaciones reservacion)
        {
            var respuesta = await _reservacionAppService.AgregarCancha(reservacion);

            if (respuesta == null)
            {
                return(Ok("Exito"));
            }
            else
            {
                return(BadRequest(respuesta));
            }
        }
Exemplo n.º 24
0
        // GET: Reservaciones/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reservaciones reservaciones = db.Reservaciones.Find(id);

            if (reservaciones == null)
            {
                return(HttpNotFound());
            }
            return(View(reservaciones));
        }
Exemplo n.º 25
0
        public bool EsDiponible(Reservaciones nuevaReservacion)
        {
            List <Reservaciones> ListaPorDia = _dbContext.Reservaciones.Where(x => x.Inicio.Day == nuevaReservacion.Inicio.Day && x.SalaId == nuevaReservacion.SalaId).OrderBy(x => x.Inicio).ToList();

            bool inicioDisponible = false;
            bool finDisponible    = false;

            //cuando no existen reuniones agendad para el dia.
            if (ListaPorDia.Count == 0)
            {
                return(true);
            }

            //si la fecha de inicio es mayor a la mayor fecha o la fecha fin sea menor a minima de inicio de finalizacion entonces true
            if (nuevaReservacion.Inicio >= ListaPorDia.Max(x => x.Fin) || nuevaReservacion.Fin <= ListaPorDia.Min(x => x.Inicio))
            {
                return(true);
            }


            foreach (var reservacion in ListaPorDia)
            {
                //verifico que la fecha inicio
                if (nuevaReservacion.Inicio >= reservacion.Fin)
                {
                    inicioDisponible = true;
                }

                if (nuevaReservacion.Fin <= reservacion.Inicio)
                {
                    finDisponible = true;
                }

                if (nuevaReservacion.Inicio == reservacion.Inicio && nuevaReservacion.Fin == reservacion.Fin)
                {
                    inicioDisponible = false;
                    finDisponible    = false;
                }
            }



            if (inicioDisponible && finDisponible)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 26
0
 public ActionResult Edit([Bind(Include = "id_reservacion,precio_reservacion,fecha_entrada_reservacion,fecha_salida_reservacion,nombre_reservacion,hotel_reservacion,habitacion_reservacion,cliente_reservacion,agencia_reservacion,descuento_reservacion")] Reservaciones reservaciones)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservaciones).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.agencia_reservacion    = new SelectList(db.Agencia, "id_agencia", "nombre_agencia", reservaciones.agencia_reservacion);
     ViewBag.cliente_reservacion    = new SelectList(db.Clientes, "id_cliente", "nombre_cliente", reservaciones.cliente_reservacion);
     ViewBag.descuento_reservacion  = new SelectList(db.Descuentos, "codigo_descuento", "codigo_descuento", reservaciones.descuento_reservacion);
     ViewBag.habitacion_reservacion = new SelectList(db.Habitaciones, "codigo_habitacion", "tipo_habotacion", reservaciones.habitacion_reservacion);
     ViewBag.hotel_reservacion      = new SelectList(db.Hoteles, "id_hotel", "nombre_hotel", reservaciones.hotel_reservacion);
     return(View(reservaciones));
 }
Exemplo n.º 27
0
        public async Task <bool> UpdateReservacion(Reservaciones reservacion)
        {
            var current = await GetReservacion(reservacion.IdReserva);

            current.EmailR         = reservacion.EmailR;
            current.NombreR        = reservacion.NombreR;
            current.ApellidosR     = reservacion.ApellidosR;
            current.FechaEntradaR  = reservacion.FechaEntradaR;
            current.FechaSalidaR   = reservacion.FechaSalidaR;
            current.TelefonoR      = reservacion.TelefonoR;
            current.HabitacionR    = reservacion.HabitacionR;
            current.EspecificaionR = reservacion.EspecificaionR;
            var rowsUpdate = await _context.SaveChangesAsync();

            return(rowsUpdate > 0);
        }
Exemplo n.º 28
0
        // GET: Reservaciones/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reservaciones reservaciones = db.Reservaciones.Find(id);

            if (reservaciones == null)
            {
                return(HttpNotFound());
            }
            ViewBag.agencia_reservacion    = new SelectList(db.Agencia, "id_agencia", "nombre_agencia", reservaciones.agencia_reservacion);
            ViewBag.cliente_reservacion    = new SelectList(db.Clientes, "id_cliente", "nombre_cliente", reservaciones.cliente_reservacion);
            ViewBag.descuento_reservacion  = new SelectList(db.Descuentos, "codigo_descuento", "codigo_descuento", reservaciones.descuento_reservacion);
            ViewBag.habitacion_reservacion = new SelectList(db.Habitaciones, "codigo_habitacion", "tipo_habotacion", reservaciones.habitacion_reservacion);
            ViewBag.hotel_reservacion      = new SelectList(db.Hoteles, "id_hotel", "nombre_hotel", reservaciones.hotel_reservacion);
            return(View(reservaciones));
        }
Exemplo n.º 29
0
        private async Task <ActionResult <bool> > Modificar([FromBody] Reservaciones reservaciones)
        {
            bool modificar = false;

            try
            {
                contexto.Database.ExecuteSqlRaw($"Delete FROM ReservacionesDetalle Where ReservacionId={reservaciones.ReservacionId}");
                foreach (var item in reservaciones.ReservacionDetalle)
                {
                    contexto.Entry(item).State = EntityState.Added;
                }
                contexto.Entry(reservaciones).State = EntityState.Modified;
                modificar = await contexto.SaveChangesAsync() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            return(modificar);
        }
Exemplo n.º 30
0
        private async Task <ActionResult <bool> > Insertar(Reservaciones reservaciones)
        {
            bool guardar = false;

            try
            {
                contexto.Reservaciones.Add(reservaciones);
                guardar = await contexto.SaveChangesAsync() > 0;

                if (guardar)
                {
                    await OcuparHabitacion(reservaciones);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(guardar);
        }