public async Task <IActionResult> GetAnuncios()
        {
            var result = await _anuncioRepositorio.RetornarAnuncios();

            if (result.Count() <= 0)
            {
                return(NotFound());
            }

            var lstAnuncios = new List <AnuncioDTO>();

            foreach (var item in result)
            {
                var anuncio = new AnuncioDTO()
                {
                    AnuncioId     = item.Id,
                    Marca         = item.Marca,
                    Modelo        = item.Modelo,
                    Versão        = item.Versao,
                    Ano           = item.Ano,
                    Quilometragem = item.Quilometragem,
                    Observacao    = item.Observacao
                };

                lstAnuncios.Add(anuncio);
            }

            return(Ok(lstAnuncios));
        }
Esempio n. 2
0
 public AnuncioDTO getById(int id)
 {
     try
     {
         Anuncio    model        = db.Anuncios.Include(x => x.catalogo).Include(x => x.catalogo.imagen).FirstOrDefault(x => x.id == id && x.estado == true);
         AnuncioDTO anuncioModel = new AnuncioDTO();
         anuncioModel.titulo          = model.titulo;
         anuncioModel.nombreContacto  = model.nombreContacto;
         anuncioModel.telefono        = model.telefono;
         anuncioModel.actCatalogo     = model.actCatalogo;
         anuncioModel.actImagen       = model.actImagen;
         anuncioModel.celularContacto = model.celularContacto;
         anuncioModel.descripcion     = model.descripcion;
         anuncioModel.id               = model.id;
         anuncioModel.path             = imageHelper.GetImageFromByteArray(model.imagen);
         anuncioModel.fechaActivacion  = model.fechaActivacion;
         anuncioModel.fechaCancelacion = model.fechaCancelacion;
         anuncioModel.categoriaId      = model.categoriaId;
         anuncioModel.categoria        = categoriasDAO.Find(model.categoriaId);
         if (model.catalogo != null)
         {
             anuncioModel.catalogo = GetCatalogo(model.catalogo);
         }
         return(anuncioModel);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public async Task <IActionResult> Deletar(int id, [FromBody] AnuncioDTO command)
        {
            try
            {
                if (id != command.AnuncioId)
                {
                    return(BadRequest());
                }

                var result = await _anuncioRepositorio.RetornarAnuncio(id);

                if (result == null)
                {
                    return(NotFound());
                }

                await _anuncioService.Deletar(id);

                return(Ok());
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 4
0
        public void CreateAnuncio()
        {
            var anuncio = new AnuncioDTO
            {
                Marca         = "Chevrolet",
                Modelo        = "Agile",
                Versao        = "1.5 DX 16V FLEX 4P AUTOMÁTICO",
                Ano           = 2018,
                Quilometragem = 25000,
                Observacao    = "Carro com único dono e o IPVA de 2020 pago."
            };

            var data = new ResponseBase
            {
                Success   = true,
                Message   = null,
                Exception = null
            };

            anuncioServiceMock.Setup(a => a.Create(anuncio)).Returns(data);

            var result = anunciosController.Post(anuncio);

            Assert.AreEqual(true, GetVal <bool>(result, "Success"));
            Assert.AreEqual(null, GetVal <string>(result, "Message"));
        }
Esempio n. 5
0
        public ActionResult Post([FromForm] AnuncioDTOPost anuncioDTOPost)
        {
            try
            {
                if (anuncioDTOPost == null || String.IsNullOrEmpty(anuncioDTOPost.Descricao) || anuncioDTOPost.ImageFile.Length <= 0 || !anuncioDTOPost.ImageFile.ContentType.Contains("image"))
                {
                    return(NotFound("Os dados do anúncio não foram preenchidos corretamente!"));
                }

                var anuncioDTO = new AnuncioDTO
                {
                    Descricao = anuncioDTOPost.Descricao,
                    IsAtivo   = anuncioDTOPost.IsAtivo,
                    Latitude  = anuncioDTOPost.Latitude,
                    Longitude = anuncioDTOPost.Longitude
                };

                using (var ms = new MemoryStream())
                {
                    anuncioDTOPost.ImageFile.CopyTo(ms);
                    var fileBytes = ms.ToArray();
                    anuncioDTO.Imagem = fileBytes;
                }

                app.Add(anuncioDTO);
                return(Ok("Anúncio inserido com sucesso!"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        public void Test2Put()
        {
            ClientConfiguration();

            var responseAll = _client.GetAsync("/api/anuncio").Result;

            responseAll.EnsureSuccessStatusCode();

            responseAll.StatusCode.Should().Be(HttpStatusCode.OK);

            string apiResponseAll = responseAll.Content.ReadAsStringAsync().Result;
            var    resultAll      = JsonConvert.DeserializeObject <List <AnuncioDTO> >(apiResponseAll);

            resultAll.Should().NotBeNullOrEmpty();

            AnuncioDTO ad = resultAll.Last();

            ad.Observacao = "Alterando Anuncio";

            HttpContent content = new StringContent(JsonConvert.SerializeObject(ad), Encoding.UTF8, "application/json");

            var response = _client.PutAsync("/api/anuncio", content).Result;

            response.EnsureSuccessStatusCode();

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            string apiResponsePut = response.Content.ReadAsStringAsync().Result;
            var    resultPut      = JsonConvert.DeserializeObject <AnuncioDTO>(apiResponsePut);

            resultPut.Should().Equals(ad);

            _client?.Dispose();
        }
Esempio n. 7
0
        public void ListAnuncios()
        {
            string marca = "Chevrolet";

            string modelo = "Agile";

            var anuncio = new AnuncioDTO
            {
                Marca         = "Chevrolet",
                Modelo        = "Agile",
                Versao        = "1.5 DX 16V FLEX 4P AUTOMÁTICO",
                Ano           = 2018,
                Quilometragem = 25000,
                Observacao    = "Carro com único dono e o IPVA de 2020 pago."
            };

            var anuncios = new List <AnuncioDTO>();

            anuncios.Add(anuncio);

            var data = new ResponseBase <IEnumerable <AnuncioDTO> >()
            {
                Success   = true,
                Data      = anuncios,
                Message   = null,
                Exception = null
            };

            anuncioServiceMock.Setup(a => a.List(marca, modelo)).Returns(data);

            var result = anunciosController.List(marca, modelo);

            Assert.AreEqual(true, GetVal <bool>(result, "Success"));
            Assert.AreEqual(1, GetVal <List <AnuncioDTO> >(result, "Data").Count);
        }
        public IActionResult Put([FromBody] AnuncioDTO anuncio)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            try
            {
                if (anuncio == null)
                {
                    return(BadRequest());
                }
                var updatedanuncio = _business.Update(anuncio);
                if (updatedanuncio == null)
                {
                    return(BadRequest());
                }
                return(new OkObjectResult(updatedanuncio));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Esempio n. 9
0
        public async Task <AnuncioDTO> Inserir(AnuncioDTO model)
        {
            model.Validate();
            if (model.Invalid)
            {
                return(await Task.FromResult(new AnuncioDTO()));
            }

            var anuncio = new Anuncio()
            {
                Marca         = model.Marca,
                Modelo        = model.Modelo,
                Versao        = model.Versão,
                Ano           = model.Ano,
                Quilometragem = model.Quilometragem,
                Observacao    = model.Observacao
            };

            var result = await _anuncioRepositorio.Inserir(anuncio);

            if (result > 0)
            {
                model.AnuncioId = result;
                return(await Task.FromResult(model));
            }
            else
            {
                return(await Task.FromResult(new AnuncioDTO()));
            }
        }
Esempio n. 10
0
        public static AnuncioEN Convert(AnuncioDTO dto)
        {
            AnuncioEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new AnuncioEN();



                    newinstance.Id             = dto.Id;
                    newinstance.Imagen         = dto.Imagen;
                    newinstance.Descripcion    = dto.Descripcion;
                    newinstance.FechaCaducidad = dto.FechaCaducidad;
                    newinstance.Tipo           = dto.Tipo;
                    newinstance.URL            = dto.URL;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
Esempio n. 11
0
        public AnuncioDTO Create(AnuncioDTO entity)
        {
            var anuncioEntity = _anuncioConverter.Parse(entity);

            anuncioEntity = _repository.Create(anuncioEntity);
            return(_anuncioConverter.Parse(anuncioEntity));
        }
Esempio n. 12
0
        public async Task <IActionResult> Post([FromBody] AnuncioDTO model)
        {
            Anuncio anuncio = new Anuncio(
                marca: model.Marca,
                modelo: model.Modelo,
                ano: model.Ano,
                versao: model.Versao,
                quilometragem: model.Quilometragem,
                observacao: model.Observacao);

            var result = await _ianuncio.AddAsync(anuncio);

            return(new ObjectResult(_mapper.Map <Anuncio, AnuncioDTO>(result)));
        }
Esempio n. 13
0
 public IActionResult Post([FromBody] AnuncioDTO anuncio)
 {
     try
     {
         if (anuncio == null)
         {
             return(BadRequest());
         }
         return(new OkObjectResult(_anuncioBusiness.Create(anuncio)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
        // GET: Administrador/Anuncios/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int        Id       = (int)id;
            AnuncioDTO response = anunciosDAO.getById(Id);

            if (response == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("Details", response));
        }
Esempio n. 15
0
        public async Task <IActionResult> Put(int id, [FromBody] AnuncioDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var anuncio = await _ianuncio.GetByIdAsync(id);

            _mapper.Map(model, anuncio);

            if (await _ianuncio.UpdateAsync(anuncio))
            {
                return(new ObjectResult(anuncio));
            }
            return(BadRequest());
        }
Esempio n. 16
0
        public ActionResult CreateNew(object sender, EventArgs e)
        {
            try
            {
                // TODO: Add insert logic here
                AnuncioDTO anuncio = new AnuncioDTO();

                var categoria = Request.Form["categoriaInput"];
                anuncio.titulo          = Request.Form["titulo"];
                anuncio.nombreContacto  = Request.Form["nombreContacto"];
                anuncio.telefono        = Request.Form["telefono"];
                anuncio.celularContacto = Request.Form["celularContacto"];
                anuncio.descripcion     = Request.Form["descripcion"];
                anuncio.imagen          = new byte[0];
                string actImagen   = Request.Form["actImagen"];
                string actCatalogo = Request.Form["actCatalogo"];
                string duracion    = Request.Form["duracion"];
                string localidad   = Request.Form["localidadInput"];
                if (actImagen != null)
                {
                    if (actImagen.Contains("true"))
                    {
                        anuncio.actImagen = true;
                        var binaryReader = new BinaryReader(Request.Files["imagen"].InputStream);
                        anuncio.imagen = binaryReader.ReadBytes(Request.Files["imagen"].ContentLength);
                    }
                }

                if (actCatalogo != null)
                {
                    if (actCatalogo.Contains("true"))
                    {
                        anuncio.actCatalogo = true;
                    }
                }
                string user = User.Identity.GetUserName();
                anunciosDAO.GuardarAnuncio(user, anuncio, categoria, duracion, localidad);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create([FromBody] AnuncioDTO command)
        {
            try
            {
                var result = await _anuncioService.Inserir(command);

                if (command.Notifications.Any())
                {
                    return(BadRequest(command.Notifications));
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 18
0
        public List <AnuncioDTO> ListarAnuncios()
        {
            try
            {
                //Mapeo de clase
                var anuncio = db.Anuncios.Include(x => x.catalogo).Include(x => x.tipoAnuncio).Where(x => x.estado == true).ToList();
                List <AnuncioDTO> anuncios = new List <AnuncioDTO>();
                if (anuncio != null)
                {
                    foreach (var item in anuncio)
                    {
                        AnuncioDTO anuncioModel = new AnuncioDTO();
                        anuncioModel.titulo          = item.titulo;
                        anuncioModel.nombreContacto  = item.nombreContacto;
                        anuncioModel.telefono        = item.telefono;
                        anuncioModel.actCatalogo     = item.actCatalogo;
                        anuncioModel.actImagen       = item.actImagen;
                        anuncioModel.celularContacto = item.celularContacto;
                        anuncioModel.descripcion     = item.descripcion;
                        anuncioModel.id               = item.id;
                        anuncioModel.path             = imageHelper.GetImageFromByteArray(item.imagen);
                        anuncioModel.fechaActivacion  = item.fechaActivacion;
                        anuncioModel.fechaCancelacion = item.fechaCancelacion;
                        if (anuncioModel.catalogo != null)
                        {
                            anuncioModel.categoria = categoriasDAO.Find(item.categoriaId);
                        }

                        anuncioModel.categoria   = categoriasDAO.Find(item.categoriaId);
                        anuncioModel.categoriaId = item.categoriaId;
                        anuncioModel.localidadId = item.localidadId;
                        anuncios.Add(anuncioModel);
                    }
                }



                return(anuncios);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 19
0
        public static AnuncioDTO Convert(AnuncioEN en)
        {
            AnuncioDTO newinstance = null;

            if (en != null)
            {
                newinstance = new AnuncioDTO();


                newinstance.Id             = en.Id;
                newinstance.Imagen         = en.Imagen;
                newinstance.Descripcion    = en.Descripcion;
                newinstance.FechaCaducidad = en.FechaCaducidad;
                newinstance.Tipo           = en.Tipo;
                newinstance.URL            = en.URL;
            }

            return(newinstance);
        }
        public ResponseBase Create(AnuncioDTO anuncio)
        {
            var response = new ResponseBase();

            try
            {
                var entity = _mapper.Map <Anuncio>(anuncio);

                _anuncioRepository.Insert(entity);
                _anuncioRepository.SaveChanges();
            }
            catch (Exception ex)
            {
                response.Success   = false;
                response.Message   = $"{ex.Message}";
                response.Exception = ex;
            }

            return(response);
        }
        public async Task <IActionResult> GetAnuncio(int id)
        {
            var result = await _anuncioRepositorio.RetornarAnuncio(id);

            if (result == null)
            {
                return(NotFound());
            }

            var anuncioDTO = new AnuncioDTO()
            {
                AnuncioId     = id,
                Marca         = result.Marca,
                Modelo        = result.Modelo,
                Versão        = result.Versao,
                Ano           = result.Ano,
                Quilometragem = result.Quilometragem,
                Observacao    = result.Observacao
            };

            return(Ok(anuncioDTO));
        }
Esempio n. 22
0
        public void GuardarAnuncio(string user, AnuncioDTO anuncio, string categoria, string duracion, string localidad)
        {
            try
            {
                int           categoriaId = Int32.Parse(categoria);
                CategoriasDTO cat         = categoriasDAO.Find(categoriaId);
                anuncio.categoria       = cat;
                anuncio.fechaActivacion = DateTime.Today;
                int            localidadId = Int32.Parse(localidad);
                LocalidadesDTO loc         = localidadesDAO.Find(localidadId);
                anuncio.localidad        = loc;
                anuncio.fechaCancelacion = anuncio.fechaActivacion.AddDays(60);

                Anuncio anuncioModel = new Anuncio();
                anuncioModel.titulo           = anuncio.titulo;
                anuncioModel.imagen           = anuncio.imagen;
                anuncioModel.descripcion      = anuncio.descripcion;
                anuncioModel.actImagen        = anuncio.actImagen;
                anuncioModel.nombreContacto   = anuncio.nombreContacto;
                anuncioModel.telefono         = anuncio.telefono;
                anuncioModel.celularContacto  = anuncio.celularContacto;
                anuncioModel.actCatalogo      = anuncio.actCatalogo;
                anuncioModel.fechaActivacion  = anuncio.fechaActivacion;
                anuncioModel.fechaCancelacion = anuncio.fechaCancelacion;

                anuncioModel.categoria = db.Categorias.Find(anuncio.categoria.id);
                anuncioModel.localidad = db.Localidades.Find(anuncio.localidad.id);
                Usuarios usuario = db.Usuarios.FirstOrDefault(x => x.correo.Equals(user));
                usuario.anuncios.Add(anuncioModel);

                db.Entry(usuario).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 23
0
        public async Task <AnuncioDTO> Alterar(AnuncioDTO model)
        {
            model.Validate();
            if (model.Invalid)
            {
                return(await Task.FromResult(new AnuncioDTO()));
            }

            var anuncio = new Anuncio()
            {
                Id            = model.AnuncioId,
                Marca         = model.Marca,
                Modelo        = model.Modelo,
                Versao        = model.Versão,
                Ano           = model.Ano,
                Quilometragem = model.Quilometragem,
                Observacao    = model.Observacao
            };

            await _anuncioRepositorio.Alterar(anuncio);

            return(await Task.FromResult(model));
        }
        public async Task <IActionResult> Update(int id, [FromBody] AnuncioDTO command)
        {
            try
            {
                if (id != command.AnuncioId)
                {
                    return(BadRequest());
                }

                var result = await _anuncioService.Alterar(command);

                if (command.Notifications.Any())
                {
                    return(BadRequest(command.Notifications));
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 25
0
        public void ReadAnuncio()
        {
            int id = 1;

            var anuncio = new AnuncioDTO
            {
                Marca         = "Chevrolet",
                Modelo        = "Agile",
                Versao        = "1.5 DX 16V FLEX 4P AUTOMÁTICO",
                Ano           = 2018,
                Quilometragem = 25000,
                Observacao    = "Carro com único dono e o IPVA de 2020 pago."
            };

            var data = new ResponseBase <AnuncioDTO>()
            {
                Success   = true,
                Data      = anuncio,
                Message   = null,
                Exception = null
            };

            anuncioServiceMock.Setup(a => a.Read(id)).Returns(data);

            var result = anunciosController.Get(id);

            var dataValue = GetVal <AnuncioDTO>(result, "Data");

            Assert.AreEqual(true, GetVal <bool>(result, "Success"));
            Assert.AreEqual("Chevrolet", dataValue.Marca);
            Assert.AreEqual("Agile", dataValue.Modelo);
            Assert.AreEqual("1.5 DX 16V FLEX 4P AUTOMÁTICO", dataValue.Versao);
            Assert.AreEqual(2018, dataValue.Ano);
            Assert.AreEqual(25000, dataValue.Quilometragem);
            Assert.AreEqual("Carro com único dono e o IPVA de 2020 pago.", dataValue.Observacao);
        }
Esempio n. 26
0
        public List <AnuncioDTO> buscar(string busqueda)
        {
            try
            {
                List <Anuncio> modelList = db.Anuncios.Include(x => x.categoria).Where(x => x.titulo.Trim().ToLower().Contains(busqueda.Trim().ToLower()) || x.nombreContacto.Trim().ToLower().Contains(busqueda.Trim().ToLower()) ||
                                                                                       x.categoria.nombre.Trim().ToLower().Contains(busqueda.Trim().ToLower()) || x.descripcion.Trim().ToLower().Contains(busqueda.Trim().ToLower())).ToList();

                List <AnuncioDTO> responseList = new List <AnuncioDTO>();
                foreach (var item in modelList)
                {
                    AnuncioDTO anuncioModel = new AnuncioDTO();
                    anuncioModel.titulo          = item.titulo;
                    anuncioModel.nombreContacto  = item.nombreContacto;
                    anuncioModel.telefono        = item.telefono;
                    anuncioModel.actCatalogo     = item.actCatalogo;
                    anuncioModel.actImagen       = item.actImagen;
                    anuncioModel.celularContacto = item.celularContacto;
                    anuncioModel.descripcion     = item.descripcion;
                    anuncioModel.id               = item.id;
                    anuncioModel.path             = imageHelper.GetImageFromByteArray(item.imagen);
                    anuncioModel.fechaActivacion  = item.fechaActivacion;
                    anuncioModel.fechaCancelacion = item.fechaCancelacion;
                    anuncioModel.categoria        = categoriasDAO.Find(item.categoriaId);
                    anuncioModel.categoriaId      = item.categoriaId;

                    responseList.Add(anuncioModel);
                }


                return(responseList);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 27
0
        public ActionResult Anuncio(int id)
        {
            AnuncioDTO anuncio = anunciosDAO.getById(id);

            return(View(anuncio));
        }
Esempio n. 28
0
        public ActionResult ShowSelected(int id)
        {
            AnuncioDTO anuncio = anunciosDAO.getById(id);

            return(PartialView("_ShowSelected", anuncio));
        }