Пример #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Hotell hotell = db.DbSetHotel.Find(id);

            db.DbSetHotel.Remove(hotell);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "HotellId,nom,adresse,numtel,dateouverture,mail,responsable")] Hotell hotell)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hotell).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hotell));
 }
Пример #3
0
        public ActionResult Create([Bind(Include = "HotellId,nom,adresse,numtel,dateouverture,mail,responsable")] Hotell hotell)
        {
            if (ModelState.IsValid)
            {
                db.DbSetHotel.Add(hotell);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hotell));
        }
Пример #4
0
        // GET: Hotells/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Hotell hotell = db.DbSetHotel.Find(id);

            if (hotell == null)
            {
                return(HttpNotFound());
            }
            return(View(hotell));
        }
Пример #5
0
        public async Task <IActionResult> AddHotel(Hotell hotel)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                Hoteles hoteldb = _dbContext.Hoteles.Where(c => c.UsuarioId == usuario.Id && c.Id == hotel.Id).FirstOrDefault();
                if (hoteldb != null)
                {
                    hoteldb.Ciudad        = hotel.Ciudad;
                    hoteldb.CodigoPostal  = hotel.CodigoPostal;
                    hoteldb.Descripcion   = hotel.Descripcion;
                    hoteldb.Direccion     = hotel.Direccion;
                    hoteldb.Email         = hotel.Email;
                    hoteldb.Estado        = hotel.Estado;
                    hoteldb.Facebook      = hotel.Facebook;
                    hoteldb.Facturacion   = hotel.Facturacion;
                    hoteldb.Instagram     = hotel.Instagram;
                    hoteldb.Latitud       = hotel.Latitud;
                    hoteldb.LinkedIn      = hotel.LinkedIn;
                    hoteldb.Longitud      = hotel.Longitud;
                    hoteldb.Nombre        = hotel.Nombre;
                    hoteldb.PalabrasClave = hotel.PalabrasClave;
                    hoteldb.Pinterest     = hotel.Pinterest;
                    hoteldb.Telefono      = hotel.Telefono;
                    hoteldb.Twitter       = hotel.Twitter;
                    hoteldb.Website       = hotel.Website;
                    hoteldb.WhatsApp      = hotel.WhatsApp;
                    _dbContext.Update(hoteldb);
                }
                else
                {
                    hoteldb = new Hoteles
                    {
                        Ciudad        = hotel.Ciudad,
                        CodigoPostal  = hotel.CodigoPostal,
                        Descripcion   = hotel.Descripcion,
                        Direccion     = hotel.Direccion,
                        Email         = hotel.Email,
                        Estado        = hotel.Estado,
                        Facebook      = hotel.Facebook,
                        Facturacion   = hotel.Facturacion,
                        Instagram     = hotel.Instagram,
                        Latitud       = hotel.Latitud,
                        LinkedIn      = hotel.LinkedIn,
                        Longitud      = hotel.Longitud,
                        Nombre        = hotel.Nombre,
                        PalabrasClave = hotel.PalabrasClave,
                        Pinterest     = hotel.Pinterest,
                        Telefono      = hotel.Telefono,
                        Twitter       = hotel.Twitter,
                        Website       = hotel.Website,
                        WhatsApp      = hotel.WhatsApp,
                        Calificacion  = 5,
                        Estatus       = true,
                        Fecha         = DateTime.Now,
                        UsuarioId     = usuario.Id
                    };
                    _dbContext.Add(hoteldb);
                }
                await _dbContext.SaveChangesAsync();

                if (hoteldb.Id > 0 && hotel.Caracteristica != null)
                {
                    var cars = _dbContext.HotelesHabitacionCaracteristica.Where(c => c.HotelId == hoteldb.Id && !hotel.Caracteristica.Contains(c.CaracteristicaId));
                    foreach (var item in cars)
                    {
                        item.Activo = false;
                        _dbContext.Update(item);
                    }
                    foreach (var item in hotel.Caracteristica)
                    {
                        if (item > 0)
                        {
                            HotelesHabitacionCaracteristica car = _dbContext.HotelesHabitacionCaracteristica.Where(c => c.HotelId == hoteldb.Id && c.CaracteristicaId == item).FirstOrDefault();
                            if (car != null)
                            {
                                car.Activo = true;
                                _dbContext.Update(car);
                            }
                            else
                            {
                                car = new HotelesHabitacionCaracteristica
                                {
                                    Activo           = true,
                                    CaracteristicaId = item,
                                    HotelId          = hoteldb.Id
                                };
                                _dbContext.Add(car);
                            }
                        }
                    }
                    await _dbContext.SaveChangesAsync();
                }
                return(new JsonResult(new Response {
                    IsSuccess = true, Message = "Se guardaron los datos correctamente", Id = hoteldb.Id
                }));
            }
            catch (Exception ex)
            {
                await _emailSender.SendEmailAsync("*****@*****.**", "Error La Pesca en Línea ", ex.ToString());

                return(new JsonResult(new Response {
                    IsSuccess = false, Message = "No se pudieron guardar los datos, intentelo más tarde."
                }));
            }
        }
Пример #6
0
 public void addHotel(Hotell e)
 {
     DbSetHotel.Add(e);
     SaveChanges();
 }