Ejemplo n.º 1
0
        public async Task <IActionResult> AddArticulo(int?id)
        {
            ViewBag.PaginaActual = "Blog";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            List <Pagina> p = new List <Pagina>();

            p.Add(new Pagina {
                Actual = false, Nombre = "Blog", Url = Url.Content("~/Blog")
            });
            p.Add(new Pagina {
                Actual = true, Nombre = "Agregar o modificar artículo", Url = Url.Content("~/Blog/AddArticulo")
            });
            ViewBag.Paginas = p;
            LaPescaEnLinea.Models.Blog blog = new LaPescaEnLinea.Models.Blog();
            if (id != null)
            {
                blog = _dbContext.Blog.Where(c => c.UsuarioId == usuario.Id && c.Id == id).FirstOrDefault();
                if (blog == null)
                {
                    blog = new LaPescaEnLinea.Models.Blog();
                }
            }
            return(View(blog));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            ViewBag.PaginaActual = "Inicio";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            return(View());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ListaHoteles()
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            var hoteles = _dbContext.Hoteles.Where(c => c.UsuarioId == usuario.Id);

            return(PartialView(hoteles));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ImagenesHabitacion(int id)
        {
            ViewBag.PaginaActual = "Habitaciones";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            var imagenes = await _dbContext.ImagenesAsociadas.Where(c => c.HabitacionId == id && c.Activo == true).Include(c => c.Imagenes).OrderByDescending(c => c.Id).ToListAsync();

            return(PartialView(imagenes));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Index()
        {
            ViewBag.PaginaActual = "Hoteles";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            List <Pagina> p = new List <Pagina>();

            p.Add(new Pagina {
                Actual = true, Nombre = "Hoteles", Url = Url.Content("~/Hoteles")
            });
            ViewBag.Paginas = p;
            return(View());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> GuardarUsuario(IFormFile Foto, string Nombre, string Puesto, string Telefono, string Password)
        {
            Response response = new Response {
                IsSuccess = true, Message = "Se actualizó correctamente tu perfil."
            };

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

                var usu = _dbContext.Usuarios.Where(c => c.Id == usuario.Id).FirstOrDefault();
                if (usu != null)
                {
                    usu.Nombre   = Nombre;
                    usu.Puesto   = Puesto;
                    usu.Telefono = Telefono;
                    usu.Password = string.IsNullOrEmpty(Password) ? usu.Password : Tools.SecurityManager.Encrypt(Password);
                    if (Foto != null && Foto.Length > 0)
                    {
                        string strFile = Tools.Generics.NameFile() + "_Id_User_" + usu.Id.ToString() + Path.GetExtension(Foto.FileName);
                        var    path    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "FileUpload", strFile);
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await Foto.CopyToAsync(stream);

                            usu.Foto = strFile;
                        }
                    }
                    _dbContext.Update(usu);
                    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 tu perfil";
            return(new JsonResult(response));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> ListaHabitaciones(int?IdHotel)
        {
            ViewBag.HotelId = IdHotel;
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            if (IdHotel != null)
            {
                var habitaciones = _dbContext.Hoteles.Where(c => c.Id == IdHotel && c.UsuarioId == usuario.Id).Include(c => c.Habitaciones);
                return(PartialView(habitaciones));
            }
            else
            {
                var habitaciones = _dbContext.Hoteles.Where(c => c.UsuarioId == usuario.Id).Include(c => c.Habitaciones);
                return(PartialView(habitaciones));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> ChangeTheme(string Tema)
        {
            Response response = new Response {
                IsSuccess = true, Message = "Se cambió tu panel de contol correctamente."
            };

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

                usuario.ColorTema = Tema;
                var usu = _dbContext.Usuarios.Where(c => c.Id == usuario.Id).FirstOrDefault();
                if (usu != null)
                {
                    usu.ColorTema = Tema;
                    _dbContext.Update(usu);
                    await _dbContext.SaveChangesAsync();

                    var claimsIdentity = new ClaimsIdentity(await AutenticacionHelper.UpdateClaims(HttpContext, _emailSender, usuario),
                                                            CookieAuthenticationDefaults.AuthenticationScheme);
                    var authProperties = new AuthenticationProperties
                    {
                        AllowRefresh = true,
                        IsPersistent = usuario.Recordar
                    };
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                                  new ClaimsPrincipal(claimsIdentity), authProperties);

                    response.Funcion = "cambio de tema";
                }
            }
            catch (Exception ex)
            {
                await _emailSender.SendEmailAsync("*****@*****.**", "Error La Pesca en Línea ", ex.Message);

                response.IsSuccess = false;
                response.Message   = "No se pudo actualizar en el servidor la información solicitada.";
            }
            return(new JsonResult(response));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> DesactivarActivar(int HabitacionId, string MovimientoActDesact)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                var hoteldb = _dbContext.Hoteles.Where(c => c.UsuarioId == usuario.Id).Select(c => c.Id);
                var habita  = _dbContext.Habitaciones.Where(c => hoteldb.Contains(c.HotelId) && c.Id == HabitacionId).FirstOrDefault();
                if (habita != null)
                {
                    Boolean movimiento = MovimientoActDesact == "A" ? true : false;
                    habita.Activo = movimiento;
                    _dbContext.Update(habita);
                    await _dbContext.SaveChangesAsync();

                    string strmensaje = MovimientoActDesact == "A" ? "activo" : "desactivo";
                    return(new JsonResult(new Response {
                        IsSuccess = true, Message = "Se " + strmensaje + " la habitación correctamente", DivTabla = "#tblHabitaciones", Url = @Url.Content("~/Habitaciones/ListaHabitaciones")
                    }));
                }
                else
                {
                    return(new JsonResult(new Response {
                        IsSuccess = false, Message = "No se encuentra la habitación que quiere desactivar"
                    }));
                }
            }
            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."
                }));
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> AddHabitacion(int?id)
        {
            ViewBag.PaginaActual = "Habitaciones";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            LaPescaEnLinea.Models.Habitaciones habitacion = new LaPescaEnLinea.Models.Habitaciones();
            var hotel = _dbContext.Hoteles.Where(c => c.UsuarioId == usuario.Id && c.Estatus == true);

            ViewBag.Hoteles = hotel;
            if (id != null)
            {
                var ids = hotel.Select(c => c.Id);
                habitacion = _dbContext.Habitaciones.Where(c => ids.Contains(c.HotelId) && c.Id == id).FirstOrDefault();
                if (habitacion == null)
                {
                    habitacion = new LaPescaEnLinea.Models.Habitaciones();
                }
            }
            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            List <Pagina> p = new List <Pagina>();

            p.Add(new Pagina {
                Actual = false, Nombre = "Habitaciones", Url = Url.Content("~/Habitaciones")
            });
            p.Add(new Pagina {
                Actual = true, Nombre = "Agregar o modificar habitación", Url = Url.Content("~/Habitaciones/AddHabitacion")
            });
            ViewBag.Paginas = p;

            var instalaciones = _dbContext.Cracteristicas.ToList().OrderBy(c => c.Nombre);

            ViewBag.Instalaciones     = instalaciones;
            ViewBag.InstalacionesDivs = instalaciones.Count() / 3;

            return(PartialView(habitacion));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> DesactivarActivar(int BlogId, string MovimientoActDesact)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                Blog blogdb = _dbContext.Blog.Where(c => c.UsuarioId == usuario.Id && c.Id == BlogId).FirstOrDefault();
                if (blogdb != null)
                {
                    Boolean movimiento = MovimientoActDesact == "A" ? true : false;
                    blogdb.Activo = movimiento;
                    _dbContext.Update(blogdb);
                    await _dbContext.SaveChangesAsync();

                    string strmensaje = MovimientoActDesact == "A" ? "activo" : "desactivo";
                    return(new JsonResult(new Response {
                        IsSuccess = true, Message = "Se " + strmensaje + " el artículo correctamente", DivTabla = "#tblBlog", Url = @Url.Content("~/Blog/ListaArticulos")
                    }));
                }
                else
                {
                    return(new JsonResult(new Response {
                        IsSuccess = false, Message = "No se encuentra el artículo que quiere desactivar"
                    }));
                }
            }
            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."
                }));
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Imagenes(int page, string strSearch, string opcion = "")
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            int             skyp = page * 9;
            List <Imagenes> img  = new List <Imagenes>();

            if (!string.IsNullOrEmpty(strSearch))
            {
                img = _dbContext.Imagenes.Where(c => c.Activo == true && c.UsuarioId == usuario.Id && c.Nombre.Contains(strSearch)).OrderByDescending(c => c.Id).Skip(skyp).Take(9).ToList();
            }
            else
            {
                img = _dbContext.Imagenes.Where(c => c.Activo == true && c.UsuarioId == usuario.Id).OrderByDescending(c => c.Id).Skip(skyp).Take(9).ToList();
            }
            ViewBag.Opcion = opcion;
            return(PartialView(img));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Index()
        {
            ViewBag.PaginaActual = "Mi cuenta";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            var usu = _dbContext.Usuarios.Where(c => c.Id == usuario.Id).FirstOrDefault() ?? new Usuarios();

            usu.Foto = string.IsNullOrEmpty(usu.Foto) ? "200x200.jpg" : usu.Foto;

            List <Pagina> p = new List <Pagina>();

            p.Add(new Pagina {
                Actual = true, Nombre = "Mi cuenta", Url = Url.Content("~/MiPerfil")
            });
            ViewBag.Paginas = p;

            return(View(usu));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Index()
        {
            ViewBag.PaginaActual = "Configuración";
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

            ViewBag.Color = usuario.ColorTema == "w" ? Url.Content("~/admin/white") : Url.Content("~/admin/black");
            List <Pagina> p = new List <Pagina>();

            p.Add(new Pagina {
                Actual = true, Nombre = "Configuración", Url = Url.Content("~/Configuracion")
            });
            ViewBag.Paginas = p;

            var config = _dbContext.Configuracion.FirstOrDefault() ?? new LaPescaEnLinea.Models.Configuracion();

            config.LogoPrincipal = string.IsNullOrEmpty(config.LogoPrincipal) ? "200x200.jpg" : config.LogoPrincipal;
            config.LogoFooter    = string.IsNullOrEmpty(config.LogoFooter) ? "200x200.jpg" : config.LogoFooter;
            return(View(config));
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
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."
                }));
            }
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> AsignarImagenes(int HotelId, int ImagenId, int?HabitacionId)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                var hotel = _dbContext.Hoteles.Where(c => c.Id == HotelId && c.UsuarioId == usuario.Id).FirstOrDefault();
                if (hotel == null)
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "No se encontro el hotel."
                    }));
                }
                var img = _dbContext.ImagenesAsociadas.Where(c => c.ImagenId == ImagenId && c.HotelId == HotelId && c.HabitacionId == HabitacionId && c.Activo == true).FirstOrDefault();
                if (img != null)
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "La imagen ya se encuentra asociada."
                    }));
                }
                var nuevaImagen = new ImagenesAsociadas
                {
                    Activo       = true,
                    HotelId      = HotelId,
                    HabitacionId = HabitacionId,
                    ImagenId     = ImagenId
                };

                _dbContext.Add(nuevaImagen);
                await _dbContext.SaveChangesAsync();

                if (nuevaImagen.Id > 0)
                {
                    if (HabitacionId != null)
                    {
                        return(new JsonResult(new Response
                        {
                            IsSuccess = true,
                            Message = "Se agrego correctamente la imagen.",
                            DivTabla = "#fotosmihotel",
                            Url = Url.Content("~/Habitaciones/ImagenesHabitacion?id=" + HabitacionId)
                        }));
                    }
                    return(new JsonResult(new Response
                    {
                        IsSuccess = true,
                        Message = "Se agrego correctamente la imagen.",
                        DivTabla = "#fotosmihotel",
                        Url = Url.Content("~/Hoteles/ImagenesHotel?id=" + HotelId) + "&opcion=seleccionar&h="
                    }));
                }
            }
            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 asociar la foto al sistema, intentelo más tarde."
                }));
            }
            return(new JsonResult(new Response
            {
                IsSuccess = false,
                Message = "No se pudo asociar la foto al sistema, intentelo más tarde."
            }));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> EliminarRelacion(int HotelId, int ImagenId, int?HabitacionId)
        {
            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var usuario = await AutenticacionHelper.GetUsuario(HttpContext, _emailSender);

                var hotel = _dbContext.Hoteles.Where(c => c.Id == HotelId && c.UsuarioId == usuario.Id).FirstOrDefault();
                if (hotel == null)
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "No se encontro el hotel."
                    }));
                }
                var img = _dbContext.ImagenesAsociadas.Where(c => c.Id == ImagenId && c.HotelId == HotelId && c.HabitacionId == HabitacionId && c.Activo == true).FirstOrDefault();
                if (img != null)
                {
                    img.Activo = false;
                    _dbContext.Update(img);
                    await _dbContext.SaveChangesAsync();
                }
                else
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = false,
                        Message = "No se encontro la imagen que se queria eliminar."
                    }));
                }
                if (HabitacionId != null)
                {
                    return(new JsonResult(new Response
                    {
                        IsSuccess = true,
                        Message = "Se eliminó correctamente la imagen.",
                        DivTabla = "#fotosmihotel",
                        Url = Url.Content("~/Habitaciones/ImagenesHabitacion?id=" + HabitacionId)
                    }));
                }
                return(new JsonResult(new Response
                {
                    IsSuccess = true,
                    Message = "Se eliminó correctamente la imagen.",
                    DivTabla = "#fotosmihotel",
                    Url = Url.Content("~/Hoteles/ImagenesHotel?id=" + HotelId)
                }));
            }
            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 eliminar la foto del hotel, intentelo más tarde."
                }));
            }
        }
Ejemplo n.º 19
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."
                }));
            }
        }
Ejemplo n.º 20
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."
                }));
            }
        }
Ejemplo n.º 21
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."
                }));
            }
        }