コード例 #1
0
        public async Task <IActionResult> AddHabitacion(Habitacion hab)
        {
            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 == hab.HotelId).Include(c => c.Habitaciones).FirstOrDefault();
                Habitaciones habita  = new Habitaciones();
                if (hoteldb != null)
                {
                    habita = hoteldb.Habitaciones.Where(c => c.Id == hab.Id).FirstOrDefault();
                    if (habita != null)
                    {
                        habita.Adultos               = hab.Adultos;
                        habita.CamaDoble             = hab.CamaDoble;
                        habita.CamaIndividual        = hab.CamaIndividual;
                        habita.CamaKingSize          = hab.CamaKingSize;
                        habita.CamaQueenSize         = hab.CamaQueenSize;
                        habita.Costo                 = hab.Costo;
                        habita.CostoAdicionalAdulto  = hab.CostoAdicionalAdulto;
                        habita.CostoAdicionalInfante = hab.CostoAdicionalInfante;
                        habita.CostoAdicionalNino    = hab.CostoAdicionalNino;
                        habita.Descripcion           = hab.Descripcion ?? "";
                        habita.Infantes              = hab.Infantes;
                        habita.MaximoAdultos         = hab.MaximoAdultos;
                        habita.MaximoInfantes        = hab.MaximoInfantes;
                        habita.MaximoNinos           = hab.MaximoNinos;
                        habita.Ninos                 = hab.Ninos;
                        habita.Titulo                = hab.Titulo;
                        habita.TotalHabitaciones     = hab.TotalHabitaciones;
                        _dbContext.Update(habita);
                    }
                    else
                    {
                        habita = new Habitaciones
                        {
                            Adultos               = hab.Adultos,
                            CamaDoble             = hab.CamaDoble,
                            CamaIndividual        = hab.CamaIndividual,
                            CamaKingSize          = hab.CamaKingSize,
                            CamaQueenSize         = hab.CamaQueenSize,
                            Costo                 = hab.Costo,
                            CostoAdicionalAdulto  = hab.CostoAdicionalAdulto,
                            CostoAdicionalInfante = hab.CostoAdicionalInfante,
                            CostoAdicionalNino    = hab.CostoAdicionalNino,
                            Descripcion           = hab.Descripcion ?? "",
                            Infantes              = hab.Infantes,
                            MaximoAdultos         = hab.MaximoAdultos,
                            MaximoInfantes        = hab.MaximoInfantes,
                            MaximoNinos           = hab.MaximoNinos,
                            Ninos                 = hab.Ninos,
                            Titulo                = hab.Titulo,
                            TotalHabitaciones     = hab.TotalHabitaciones,
                            Activo                = true,
                            Calificacion          = 0,
                            HotelId               = hab.HotelId,
                            PalabrasClave         = ""
                        };
                        _dbContext.Add(habita);
                    }
                    await _dbContext.SaveChangesAsync();

                    if (habita.Id > 0 && hab.Caracteristica != null)
                    {
                        var cars = _dbContext.HotelesHabitacionesCaracteristicas.Where(c => c.HabitacionId == habita.Id && !hab.Caracteristica.Contains(c.CaracteristicaId));
                        foreach (var item in cars)
                        {
                            item.Activo = false;
                            _dbContext.Update(item);
                        }
                        foreach (var item in hab.Caracteristica)
                        {
                            if (item > 0)
                            {
                                HotelesHabitacionesCaracteristicas car = _dbContext.HotelesHabitacionesCaracteristicas.Where(c => c.HabitacionId == habita.Id && c.CaracteristicaId == item).FirstOrDefault();
                                if (car != null)
                                {
                                    car.Activo = true;
                                    _dbContext.Update(car);
                                }
                                else
                                {
                                    car = new HotelesHabitacionesCaracteristicas
                                    {
                                        Activo           = true,
                                        CaracteristicaId = item,
                                        HabitacionId     = habita.Id
                                    };
                                    _dbContext.Add(car);
                                }
                            }
                        }
                        await _dbContext.SaveChangesAsync();
                    }
                    return(new JsonResult(new Response {
                        IsSuccess = true, Message = "Se guardaron los datos correctamente", Id = habita.Id
                    }));
                }
                return(new JsonResult(new Response {
                    IsSuccess = false, Message = "No se encontro el hotel, intentelo más tarde."
                }));
            }
            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."
                }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> AddHotel(Hotel 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.HotelesHabitacionesCaracteristicas.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)
                        {
                            HotelesHabitacionesCaracteristicas car = _dbContext.HotelesHabitacionesCaracteristicas.Where(c => c.HotelId == hoteldb.Id && c.CaracteristicaId == item).FirstOrDefault();
                            if (car != null)
                            {
                                car.Activo = true;
                                _dbContext.Update(car);
                            }
                            else
                            {
                                car = new HotelesHabitacionesCaracteristicas
                                {
                                    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."
                }));
            }
        }