public ActionResult Eliminar(int id)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             categoria categoria = db.categoria.Find(id);
             db.categoria.Remove(categoria);
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La categoria fue eliminada."
             };
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             ModelState.AddModelError("Error al eliminar el categoria.", e);
             return(View());
         }
     }
 }
 public ActionResult Agregar(categoria h)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             db.categoria.Add(h);
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La categoria fue agregada."
             };
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al agregar la categoria."
             };
             return(View());
         }
     }
 }
 public ActionResult Eliminar(int id)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             hotel hotel = db.hotel.Find(id);
             db.hotel.Remove(hotel);
             db.SaveChanges();
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al eliminar el hotel."
             };
             return(View());
         }
     }
 }
 public ActionResult Editar(categoria h)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             categoria categoria = db.categoria.Find(h.id);
             categoria.nombre      = h.nombre;
             categoria.descripcion = h.descripcion;
             categoria.iva         = h.iva;
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La categoria fue actualizada."
             };
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al agregar la categoria."
             };
             return(View());
         }
     }
 }
 public ActionResult Editar(hotel h)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         List <categoria> categorias = db.categoria.ToList();
         ViewData["listaCategoria"] = categorias;
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             hotel hotel = db.hotel.Find(h.id);
             hotel.nombre             = h.nombre;
             hotel.telefono           = h.telefono;
             hotel.fecha_construccion = h.fecha_construccion;
             hotel.direccion          = h.direccion;
             hotel.categoria_id       = h.categoria_id;
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "El hotel fue actualizado."
             };
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al editar el hotel."
             };
             return(View());
         }
     }
 }
 public ActionResult Agregar(hotel h)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         List <categoria> categorias = db.categoria.ToList();
         ViewData["listaCategoria"] = categorias;
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             db.hotel.Add(h);
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "El hotel fue agregado satisfactoriamente."
             };
             return(RedirectToAction("Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al agregar el hotel."
             };
             return(View());
         }
     }
 }
 public ActionResult Eliminar(int id)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             habitacion h = db.habitacion.Find(id);
             db.habitacion.Remove(h);
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La categoria fue eliminada."
             };
             return(RedirectToAction("Ver", "Hotel", new { id = h.hotel_id }));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al agregar la categoria."
             };
             return(RedirectToAction("Inicio", "Hotel"));
         }
     }
 }
 public ActionResult Editar(habitacion h)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             habitacion hab = db.habitacion.Find(h.id);
             hab.codigo = h.codigo.ToUpper();
             hab.precio = h.precio;
             hab.clase  = h.clase;
             db.SaveChanges();
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La habitación fue actualizada."
             };
             return(RedirectToAction("Ver", "Hotel", new { id = h.hotel_id }));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al editar la habitación."
             };
             return(RedirectToAction("Ver", "Hotel", new { id = h.hotel_id }));
         }
     }
 }
Beispiel #9
0
 public ActionResult Inicio(reserva r)
 {
     using (hotelesEntidad db = new hotelesEntidad())
     {
         if (!ModelState.IsValid)
         {
             return(View());
         }
         try
         {
             int contador = db.reserva.Where(c => c.fechaInicio >= r.fechaInicio)
                            .Where(c => c.fechaTermino <= r.fechaTermino)
                            .Where(c => c.habitacion_id == r.habitacion_id).Count();
             if (contador == 0)
             {
                 db.reserva.Add(r);
                 db.SaveChanges();
                 TempData["Mensaje"] = new Mensajes()
                 {
                     Clase = "alert-success", Titulo = "Perfecto!", Mensaje = "La reserva fue creada."
                 };
             }
             else
             {
                 TempData["Mensaje"] = new Mensajes()
                 {
                     Clase = "alert-danger", Titulo = "Error!", Mensaje = "Existen clientes en este horario, seleccionar otro."
                 }
             };
             return(RedirectToAction("Inicio", "Inicio"));
         }
         catch (Exception e)
         {
             TempData["Mensaje"] = new Mensajes()
             {
                 Clase = "alert-danger", Titulo = "Error!", Mensaje = "Error al agregar la reserva."
             };
             return(RedirectToAction("Inicio", "Inicio"));
         }
     }
 }