Exemplo n.º 1
0
        public async Task <JsonResult> CreatePostsByAdvertiser(AnunciosDTO posts)
        {
            Result <WrapperSimpleTypesDTO> result = new Result <WrapperSimpleTypesDTO>();

            try
            {
                AnunciantesServices advertiserService = new AnunciantesServices();

                posts.CodigoAnunciante        = UserLoggedIn().PersonaDelUsuario.AnuncianteDeLaPersona.Consecutivo;
                posts.CodigoIdiomaUsuarioBase = UserLoggedIn().PersonaDelUsuario.CodigoIdioma;

                if (posts.Consecutivo != 0)
                {
                    posts.AnunciosPaises.ToList().ForEach(c => c.CodigoAnuncio     = posts.Consecutivo);
                    posts.CategoriasAnuncios.ToList().ForEach(c => c.CodigoAnuncio = posts.Consecutivo);
                    result.obj = await advertiserService.ModificarAnuncio(posts);
                }
                else
                {
                    result.obj = await advertiserService.CrearAnuncio(posts);
                }

                if (result.obj == null)
                {
                    return(Json(Helper.returnErrorSaveObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
                }

                return(Json(Helper.returnSuccessObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(Helper.returnErrorSaveObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
        }
        public async Task AnunciantesServices_BuscaAnuncioPaisPorConsecutivo_ShouldList()
        {
            AnunciantesServices anuncianteServices = new AnunciantesServices();

            AnunciosDTO anuncio = new AnunciosDTO
            {
                Consecutivo = 3
            };

            AnunciosDTO anuncioBuscado = await anuncianteServices.BuscarAnuncioPorConsecutivo(anuncio);

            Assert.IsNotNull(anuncioBuscado);
        }
        public async Task AnuncianteServices_EliminarAnuncio_ShouldDelete()
        {
            AnunciantesServices anuncianteServices = new AnunciantesServices();

            AnunciosDTO anuncioParaBorrar = new AnunciosDTO
            {
                Consecutivo = 7
            };

            WrapperSimpleTypesDTO wrapper = await anuncianteServices.EliminarAnuncio(anuncioParaBorrar);

            Assert.IsNotNull(wrapper);
            Assert.IsTrue(wrapper.Exitoso);
        }
        public async Task <WrapperSimpleTypesDTO> EliminarArchivoAnuncio(AnunciosDTO anuncioArchivoParaEliminar)
        {
            if (anuncioArchivoParaEliminar == null)
            {
                throw new ArgumentNullException("No puedes eliminar un archivoAnuncio si anuncioArchivoParaEliminar es nulo!.");
            }
            if (anuncioArchivoParaEliminar.Consecutivo <= 0 || anuncioArchivoParaEliminar.CodigoArchivo <= 0)
            {
                throw new ArgumentException("anuncioArchivoParaEliminar vacio y/o invalido!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            WrapperSimpleTypesDTO wrapperEliminarArchivoAnuncio = await client.PostAsync <AnunciosDTO, WrapperSimpleTypesDTO>("Anunciantes/EliminarArchivoAnuncio", anuncioArchivoParaEliminar);

            return(wrapperEliminarArchivoAnuncio);
        }
        public async Task <WrapperSimpleTypesDTO> AumentarContadorClickDeUnAnuncio(AnunciosDTO anuncioParaAumentar)
        {
            if (anuncioParaAumentar == null)
            {
                throw new ArgumentNullException("No puedes aumentar el contador de un anuncio si anuncioParaAumentar es nulo!.");
            }
            if (anuncioParaAumentar.Consecutivo <= 0)
            {
                throw new ArgumentException("anuncioParaAumentar vacio y/o invalido!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            WrapperSimpleTypesDTO wrapperAumentarContadorClickDeUnAnuncio = await client.PostAsync <AnunciosDTO, WrapperSimpleTypesDTO>("Anunciantes/AumentarContadorClickDeUnAnuncio", anuncioParaAumentar);

            return(wrapperAumentarContadorClickDeUnAnuncio);
        }
        public async Task <WrapperSimpleTypesDTO> ModificarAnuncio(AnunciosDTO anuncioParaModificar)
        {
            if (anuncioParaModificar == null)
            {
                throw new ArgumentNullException("No puedes modificar un anuncio si anuncioParaModificar es nulo!.");
            }
            if (anuncioParaModificar.Consecutivo <= 0 || anuncioParaModificar.FechaInicio == DateTime.MinValue)
            {
                throw new ArgumentException("anuncioParaModificar vacio y/o invalido!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            WrapperSimpleTypesDTO wrapperModificarAnuncio = await client.PostAsync <AnunciosDTO, WrapperSimpleTypesDTO>("Anunciantes/ModificarAnuncio", anuncioParaModificar);

            return(wrapperModificarAnuncio);
        }
        public async Task <List <AnunciosDTO> > ListarAnunciosDeUnAnunciante(AnunciosDTO anuncioParaListar)
        {
            if (anuncioParaListar == null)
            {
                throw new ArgumentNullException("No puedes listar los anuncios si anuncioParaListar es nulo!.");
            }
            if (anuncioParaListar.SkipIndexBase < 0 || anuncioParaListar.TakeIndexBase <= 0 || anuncioParaListar.CodigoAnunciante <= 0 || anuncioParaListar.IdiomaBase == Idioma.SinIdioma)
            {
                throw new ArgumentException("anuncioParaListar vacio y/o invalido!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            List <AnunciosDTO> listarInformacionAnuncios = await client.PostAsync <AnunciosDTO, List <AnunciosDTO> >("Anunciantes/ListarAnunciosDeUnAnunciante", anuncioParaListar);

            return(listarInformacionAnuncios);
        }
        public async Task <AnunciosDTO> BuscarAnuncioPorConsecutivo(AnunciosDTO anuncioParaBuscar)
        {
            if (anuncioParaBuscar == null)
            {
                throw new ArgumentNullException("No puedes buscar un anuncio si anuncioParaBuscar es nulo!.");
            }
            if (anuncioParaBuscar.Consecutivo <= 0)
            {
                throw new ArgumentException("anuncioParaBuscar vacio y/o invalido!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            AnunciosDTO anuncioBuscado = await client.PostAsync("Anunciantes/BuscarAnuncioPorConsecutivo", anuncioParaBuscar);

            return(anuncioBuscado);
        }
        public async Task AnunciantesServices_ListarAnunciosDeUnAnunciante_ShouldList()
        {
            AnunciantesServices anuncianteServices = new AnunciantesServices();

            AnunciosDTO anuncio = new AnunciosDTO
            {
                SkipIndexBase           = 0,
                TakeIndexBase           = 20,
                CodigoAnunciante        = 1,
                CodigoIdiomaUsuarioBase = 1
            };

            List <AnunciosDTO> lstAnuncios = await anuncianteServices.ListarAnunciosDeUnAnunciante(anuncio);

            Assert.IsNotNull(lstAnuncios);
            Assert.IsTrue(lstAnuncios.Count > 0);
            Assert.IsTrue(lstAnuncios.TrueForAll(x => x.Anunciantes == null));
            Assert.IsTrue(lstAnuncios.TrueForAll(x => x.Archivos == null));
        }
Exemplo n.º 10
0
        public async Task <JsonResult> DeletePostsByAdvertiser(AnunciosDTO ad)
        {
            Result <WrapperSimpleTypesDTO> result = new Result <WrapperSimpleTypesDTO>();

            try
            {
                AnunciantesServices advertiserService = new AnunciantesServices();
                result.obj = await advertiserService.EliminarAnuncio(new AnunciosDTO { Consecutivo = ad.Consecutivo });

                if (result.obj == null)
                {
                    return(Json(Helper.returnErrorDelete(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
                }

                return(Json(Helper.returnSuccessDeleteObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(Helper.returnErrorDelete(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
        }
        public async Task AnunciantesServices_CrearAnuncio_ShouldCreate()
        {
            AnunciantesServices anuncianteServices = new AnunciantesServices();

            AnunciosDTO anuncios = new AnunciosDTO
            {
                CodigoAnunciante   = 1,
                Vencimiento        = new DateTime(2020, 1, 1),
                NumeroApariciones  = 1000,
                CodigoArchivo      = 11,
                UrlPublicidad      = "hollaaaa",
                AnunciosContenidos = new List <AnunciosContenidosDTO>
                {
                    new AnunciosContenidosDTO {
                        Titulo = "holaa", CodigoIdioma = 1
                    },
                    new AnunciosContenidosDTO {
                        Titulo = "hi", CodigoIdioma = 2
                    }
                },
                AnunciosPaises = new List <AnunciosPaisesDTO>
                {
                    new AnunciosPaisesDTO {
                        CodigoPais = 1
                    }
                },
                CategoriasAnuncios = new List <CategoriasAnunciosDTO>
                {
                    new CategoriasAnunciosDTO {
                        CodigoCategoria = 3
                    }
                }
            };

            WrapperSimpleTypesDTO wrapper = await anuncianteServices.CrearAnuncio(anuncios);

            Assert.IsNotNull(wrapper);
            Assert.IsTrue(wrapper.Exitoso);
        }
Exemplo n.º 12
0
        public async Task <JsonResult> UpdateCounterAdSeen(AnunciosDTO ad)
        {
            Result <WrapperSimpleTypesDTO> result = new Result <WrapperSimpleTypesDTO>();

            try
            {
                AnunciantesServices advertiserService = new AnunciantesServices();
                result.obj = await advertiserService.AumentarContadorClickDeUnAnuncio(ad);

                if (result.obj != null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(Helper.returnErrorSaveObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(Helper.returnErrorSaveObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 13
0
        public async Task <JsonResult> GetPostsByAdvertiser(AnunciosDTO posts)
        {
            Result <AnunciosDTO> result = new Result <AnunciosDTO>();

            try
            {
                AnunciantesServices advertiserService = new AnunciantesServices();
                AnunciosDTO         postToSearch      = new AnunciosDTO();
                postToSearch.Consecutivo = posts.Consecutivo;

                result.obj = await advertiserService.BuscarAnuncioPorConsecutivo(postToSearch);

                if (result.obj == null)
                {
                    return(Json(Helper.returnErrorObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(Helper.returnErrorObj(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 14
0
        public async Task <JsonResult> GetListPostsByAdvertiser(AnunciosDTO posts)
        {
            Result <AnunciosDTO> result = new Result <AnunciosDTO>();

            try
            {
                AnunciantesServices categoryService = new AnunciantesServices();
                var ass = UserLoggedIn();
                posts.CodigoAnunciante        = UserLoggedIn().PersonaDelUsuario.AnuncianteDeLaPersona.Consecutivo;
                posts.CodigoIdiomaUsuarioBase = UserLoggedIn().PersonaDelUsuario.CodigoIdioma;
                result.list = await categoryService.ListarAnunciosDeUnAnunciante(posts);

                if (result.list == null)
                {
                    return(Json(Helper.returnErrorList(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(Helper.returnErrorList(UserLoggedIn().PersonaDelUsuario.CodigoIdioma), JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <WrapperSimpleTypesDTO> CrearAnuncio(AnunciosDTO anuncioParaCrear)
        {
            if (anuncioParaCrear == null || anuncioParaCrear.AnunciosContenidos == null || anuncioParaCrear.AnunciosPaises == null || anuncioParaCrear.CategoriasAnuncios == null)
            {
                throw new ArgumentNullException("No puedes crear un anuncio si anuncioParaCrear, AnunciosContenidos, AnunciosPaises o CategoriasAnuncios son nulos!.");
            }
            if (anuncioParaCrear.CodigoAnunciante <= 0 || anuncioParaCrear.CodigoTipoAnuncio <= 0 || anuncioParaCrear.FechaInicio == DateTime.MinValue)
            {
                throw new ArgumentException("anuncioParaCrear vacio y/o invalido!.");
            }
            else if (anuncioParaCrear.AnunciosContenidos.Count <= 0 ||
                     !anuncioParaCrear.AnunciosContenidos.All(x => x.CodigoIdioma > 0 && !string.IsNullOrWhiteSpace(x.Titulo)))
            {
                throw new ArgumentException("AnuncioContenido del anuncioParaCrear vacio y/o invalido!.");
            }
            else if (anuncioParaCrear.AnunciosPaises.Count <= 0 ||
                     !anuncioParaCrear.AnunciosPaises.All(x => x.CodigoPais > 0))
            {
                throw new ArgumentException("AnuncioPais del anuncioParaCrear vacio y/o invalido!.");
            }
            else if (anuncioParaCrear.CategoriasAnuncios.Count <= 0 ||
                     !anuncioParaCrear.CategoriasAnuncios.All(x => x.CodigoCategoria > 0))
            {
                throw new ArgumentException("CategoriasAnuncio del anuncioParaCrear vacio y/o invalido!.");
            }
            else if (anuncioParaCrear.Archivos != null)
            {
                throw new ArgumentException("Usa CrearArchivoStream en ArchivosService para crear el archivo o mataras la memoria del servidor!.");
            }

            IHttpClient client = ConfigurarHttpClient();

            WrapperSimpleTypesDTO wrapperCrearAnuncio = await client.PostAsync <AnunciosDTO, WrapperSimpleTypesDTO>("Anunciantes/CrearAnuncio", anuncioParaCrear);

            return(wrapperCrearAnuncio);
        }