コード例 #1
0
ファイル: HomeController.cs プロジェクト: jars98/SistemaHotel
        public async Task <IActionResult> Suscribirme(string txtEmail)
        {
            try
            {
                var objSuscripcion = _dbContext.Suscripciones.Where(c => c.Email == txtEmail).FirstOrDefault();
                if (objSuscripcion != null)
                {
                    objSuscripcion.Activo = true;
                    _dbContext.Update(objSuscripcion);
                }
                else
                {
                    _dbContext.Add(new Suscripciones
                    {
                        Activo = true,
                        Email  = txtEmail
                    });
                }
                await _dbContext.SaveChangesAsync();

                return(new JsonResult(new Response {
                    IsSuccess = true, Message = "Se suscribió al boletín correctamente."
                }));
            }
            catch (Exception ex)
            {
                await _emailSender.SendEmailAsync("*****@*****.**", "Error La Pesca en Línea ", ex.Message);

                return(new JsonResult(new Response {
                    IsSuccess = false, Message = "No se pudo suscribir por el momento, intentelo más tarde."
                }));
            }
        }
コード例 #2
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."
                }));
            }
        }
コード例 #3
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."
                }));
            }
        }
コード例 #4
0
        public async Task <IActionResult> GuardarInformacion(IFormFile LogoPrincipal, IFormFile LogoFooter, string Direccion, string AgenciaHotel,
                                                             string Telefono, string Twitter, string Facebook, string PaginaWeb, string Tripadvisor, string Linkedin)
        {
            Response response = new Response {
                IsSuccess = true, Message = "Se actualizó correctamente la configuración."
            };

            try
            {
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                string logoPrincipal = "";
                string logoFootoer   = "";
                if (LogoPrincipal != null && LogoPrincipal.Length > 0)
                {
                    string strFile = Tools.Generics.NameFile() + "_Id_Logo_" + usuario.Id.ToString() + Path.GetExtension(LogoPrincipal.FileName);
                    var    path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "FileUpload", strFile);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await LogoPrincipal.CopyToAsync(stream);

                        logoPrincipal = strFile;
                    }
                }
                if (LogoFooter != null && LogoFooter.Length > 0)
                {
                    string strFile = Tools.Generics.NameFile() + "_Id_Logo_" + usuario.Id.ToString() + Path.GetExtension(LogoFooter.FileName);
                    var    path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "FileUpload", strFile);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await LogoFooter.CopyToAsync(stream);

                        logoFootoer = strFile;
                    }
                }
                Configuracion config = _dbContext.Configuracion.FirstOrDefault();
                if (config != null)
                {
                    config.AgenciaHotel  = AgenciaHotel;
                    config.Direccion     = Direccion;
                    config.Facebook      = Facebook;
                    config.Linkedin      = Linkedin;
                    config.PaginaWeb     = PaginaWeb;
                    config.Telefono      = Telefono;
                    config.Tripadvisor   = Tripadvisor;
                    config.Twitter       = Twitter;
                    config.LogoPrincipal = string.IsNullOrEmpty(logoPrincipal) ? config.LogoPrincipal : logoPrincipal;
                    config.LogoFooter    = string.IsNullOrEmpty(logoFootoer) ? config.LogoFooter : logoFootoer;


                    _dbContext.Update(config);
                    await _dbContext.SaveChangesAsync();

                    return(new JsonResult(response));
                }
                else
                {
                    config = new Configuracion
                    {
                        AgenciaHotel  = AgenciaHotel,
                        Direccion     = Direccion,
                        Facebook      = Facebook,
                        Linkedin      = Linkedin,
                        PaginaWeb     = PaginaWeb,
                        Telefono      = Telefono,
                        Tripadvisor   = Tripadvisor,
                        Twitter       = Twitter,
                        LogoPrincipal = logoPrincipal,
                        LogoFooter    = logoFootoer
                    };
                    _dbContext.Add(config);
                    await _dbContext.SaveChangesAsync();

                    return(new JsonResult(response));
                }
            }
            catch (Exception ex)
            {
                await _emailSender.SendEmailAsync("*****@*****.**", "Error La Pesca en Línea ", ex.ToString());
            }
            response.IsSuccess = false;
            response.Message   = "No se pudo actualizar la configuración";
            return(new JsonResult(response));
        }
コード例 #5
0
        public async Task <IActionResult> UploadImagen(string Nombre, int?Id, IFormFile file)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                if (Id != null && file == null)
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "Debe seleccionar la foto que quiere subir al sistema."
                    }));
                }
                string strFile   = "";
                bool   saveImage = false;
                var    usuario   = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                if (file != null && file.Length > 0)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ImagesUpload");
                    strFile = await ImagenesHelper.UploadAsync(path, file, usuario.Id, _emailSender);

                    if (string.IsNullOrEmpty(strFile))
                    {
                        return(new JsonResult(new Response
                        {
                            IsSuccess = false,
                            Message = "No se pudo subir la foto al sistema, intentelo más tarde."
                        }));
                    }
                    var pathSource = Path.Combine(path, strFile);
                    path      = Path.Combine(path, "mini", strFile);
                    saveImage = await ImagenesHelper.ResizeSaveImage(pathSource, path, Convert.ToUInt32(600), Convert.ToUInt32(300), _emailSender);

                    if (saveImage == false)
                    {
                        return(new JsonResult(new Response
                        {
                            IsSuccess = false,
                            Message = "No se pudo subir la foto al sistema, intentelo más tarde."
                        }));
                    }
                }

                if ((file != null && saveImage == true) || (file == null && saveImage == false))
                {
                    if (Id == null)
                    {
                        var img = new Imagenes
                        {
                            Activo       = true,
                            BlogId       = null,
                            HabitacionId = null,
                            HotelId      = null,
                            Imagen       = strFile,
                            Nombre       = Nombre,
                            ServicioId   = null,
                            UsuarioId    = usuario.Id
                        };
                        _dbContext.Add(img);
                    }
                    else
                    {
                        var img = _dbContext.Imagenes.Where(c => c.Id == Id && c.UsuarioId == usuario.Id).FirstOrDefault();
                        if (img != null)
                        {
                            if (!string.IsNullOrEmpty(strFile))
                            {
                                img.Imagen = strFile;
                            }
                            img.Nombre = Nombre;
                            _dbContext.Update(img);
                        }
                        else
                        {
                            return(new JsonResult(new Response
                            {
                                IsSuccess = false,
                                Message = "No se encontro la foto que intenta actualizar."
                            }));
                        }
                    }
                    await _dbContext.SaveChangesAsync();

                    return(new JsonResult(new Response
                    {
                        IsSuccess = true,
                        Message = "Se guardo la foto correctamente.",
                        DivTabla = "#demo-test-gallery",
                        Url = Url.Content("~/Galeria/Imagenes?page=0")
                    }));
                }
                else
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "No se pudo subir la foto al sistema, 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 pudo subir la foto al sistema, intentelo más tarde."
                }));
            }
        }
コード例 #6
0
        public async Task <IActionResult> AddArticulo(int?Id, string Titulo, string Descripcion, string Tags, string MetaKeys, string Categoria,
                                                      string Video, IFormFile Imagen, string Post, string Tipo)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                Blog   blogdb          = null;
                string ImagenPrincipal = "";
                if (Id != null)
                {
                    blogdb = _dbContext.Blog.Where(c => c.UsuarioId == usuario.Id && c.Id == Id).FirstOrDefault();
                }
                if (Imagen != null && Imagen.Length > 0)
                {
                    string strFile = Tools.Generics.NameFile() + "_ImgBlog_" + usuario.Id.ToString() + Path.GetExtension(Imagen.FileName);
                    var    path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "FileUpload", strFile);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await Imagen.CopyToAsync(stream);

                        ImagenPrincipal = strFile;
                    }
                }
                if (blogdb != null)
                {
                    blogdb.Activo            = true;
                    blogdb.Categoria         = Categoria;
                    blogdb.Descripcion       = Descripcion;
                    blogdb.FechaModificacion = DateTime.Now;
                    blogdb.Imagen            = string.IsNullOrEmpty(ImagenPrincipal)? blogdb.Imagen : ImagenPrincipal;
                    blogdb.MetaKeys          = MetaKeys;
                    blogdb.Post      = Post;
                    blogdb.Tags      = Tags;
                    blogdb.Tipo      = Tipo;
                    blogdb.Titulo    = Titulo;
                    blogdb.UsuarioId = usuario.Id;
                    blogdb.Video     = Video;
                    _dbContext.Update(blogdb);
                }
                else
                {
                    blogdb = new Blog
                    {
                        Activo            = true,
                        Categoria         = Categoria,
                        Descripcion       = Descripcion,
                        FechaModificacion = DateTime.Now,
                        Imagen            = ImagenPrincipal,
                        MetaKeys          = MetaKeys,
                        Post        = Post,
                        Tags        = Tags,
                        Tipo        = Tipo,
                        Titulo      = Titulo,
                        UsuarioId   = usuario.Id,
                        Video       = Video,
                        Consultas   = 0,
                        Fecha       = DateTime.Now,
                        MeGusta     = 5,
                        Comentarios = 0
                    };
                    _dbContext.Add(blogdb);
                }
                await _dbContext.SaveChangesAsync();

                return(new JsonResult(new Response {
                    IsSuccess = true, Message = "Se guardaron los datos correctamente", Id = blogdb.Id, Url = Url.Content("~/Blog"), Funcion = "guardadoyredirige"
                }));
            }
            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."
                }));
            }
        }