Esempio n. 1
0
        public Models.TbAnuncio InativarAnuncio(int IdAnuncio)
        {
            Models.TbAnuncio UserAnuncio = ctx.TbAnuncio.First(x => x.IdAnuncio == IdAnuncio);
            UserAnuncio.DsSituacao = "Inativo";

            ctx.SaveChanges();
            return(UserAnuncio);
        }
Esempio n. 2
0
 public Models.TbAnuncio ConsultarAnuncioDetalhado(int?IdAnuncio)
 {
     Models.TbAnuncio resp = ctx.TbAnuncio.Include(x => x.IdUsuarioNavigation).Include(x => x.TbImagem)
                             .Include(x => x.IdUsuarioNavigation)
                             .Include(x => x.TbPerguntaResposta)
                             .FirstOrDefault(x => x.IdAnuncio == IdAnuncio);
     return(resp);
 }
Esempio n. 3
0
 public void DeletarAnuncio(int IdAnuncio)
 {
     Models.TbAnuncio deletar = ctx.TbAnuncio.Include(x => x.TbImagem)
                                .Include(x => x.TbPerguntaResposta)
                                .Include(x => x.TbFavorito)
                                .FirstOrDefault(x => x.IdAnuncio == IdAnuncio);
     ctx.Remove(deletar);
     ctx.SaveChanges();
 }
Esempio n. 4
0
        public Models.TbAnuncio AnuncioVendido(int IdAnuncio)
        {
            Models.TbAnuncio UserAnuncio = ctx.TbAnuncio.First(x => x.IdAnuncio == IdAnuncio);
            UserAnuncio.BtVendido  = true;
            UserAnuncio.DsSituacao = "Vendido";

            ctx.SaveChanges();
            return(UserAnuncio);
        }
Esempio n. 5
0
 public Models.TbAnuncio ConsultadoAnuncioDetalhado(int?IdAnuncio)
 {
     validadores.ValidarId(IdAnuncio);
     Models.TbAnuncio resp = databaseAnuncio.ConsultarAnuncioDetalhado(IdAnuncio);
     if (resp == null)
     {
         throw new ArgumentException("Anuncio não encontrado.");
     }
     return(resp);
 }
Esempio n. 6
0
 public void DeletarAnuncio(int IdAnuncio, int IdUsuario)
 {
     validadores.ValidarId(IdAnuncio);
     validadores.ValidarId(IdUsuario);
     Models.TbAnuncio ValidarUsuario = databaseAnuncio.ConsultarAnuncioDetalhado(IdAnuncio);
     if (ValidarUsuario.IdUsuario != IdUsuario)
     {
         throw new ArgumentException("Você não é o dono desse anuncio.");
     }
     databaseAnuncio.DeletarAnuncio(IdAnuncio);
 }
Esempio n. 7
0
 public ActionResult <Models.Response.AnuncioRoupasResponse.AnuncioDetalhado> ConsultarAnuncioDetalhado(int IdAnuncio)
 {
     try
     {
         Models.TbAnuncio resp = businessAnuncio.ConsultadoAnuncioDetalhado(IdAnuncio);
         return(conversorAnuncio.AnuncioDetalhadoResponse(resp));
     }
     catch (System.Exception ex)
     {
         return(NotFound(new Models.Response.Erro(404, ex.Message)));
     }
 }
Esempio n. 8
0
 public ActionResult <Models.Response.AnuncioRoupasResponse.MeusAnuncios> InativarAnuncio(int IdAnuncio)
 {
     try
     {
         Models.TbAnuncio resp = businessAnuncio.InativarAnuncio(IdAnuncio);
         return(conversorAnuncio.ConversorMeusAnunciosParaResponse(resp));
     }
     catch (System.Exception ex)
     {
         return(NotFound(new Models.Response.Erro(404, ex.Message)));
     }
 }
Esempio n. 9
0
 public ActionResult <Models.Response.AnuncioRoupasResponse.Anuncio> AlterarAnuncio(Models.Request.AnuncioRoupasRequest.AlterarAnuncio a)
 {
     try
     {
         Models.TbAnuncio NovoAnuncio = conversorAnuncio.AlterarAnuncioParaTabela(a);
         Models.TbAnuncio resp        = businessAnuncio.AlterarAnuncio(NovoAnuncio);
         return(conversorAnuncio.ConversorAnuncioResponse(resp));
     }
     catch (System.Exception ex)
     {
         return(BadRequest(new Models.Response.Erro(400, ex.Message)));
     }
 }
Esempio n. 10
0
        public Models.TbImagem InserirImagem(Models.TbImagem req)
        {
            Models.TbAnuncio val = businessAnuncio.ConsultadoAnuncioDetalhado(req.IdAnuncio);
            if (val.TbImagem.Count >= 10)
            {
                throw new ArgumentException("Você só pode inserir 10 imagens por anuncio.");
            }
            if (val.TbImagem.Count == 1 && val.TbImagem.ToList()[0].ImgAnuncio == "semimagem.png")
            {
                databaseImagem.ApagarImagem(val.TbImagem.FirstOrDefault().IdImagem, val.TbImagem.FirstOrDefault().IdAnuncio);
            }

            return(databaseImagem.InserirImagem(req));
        }
Esempio n. 11
0
 public ActionResult <Models.Response.AnuncioRoupasResponse.Anuncio> Anunciar([FromForm] Models.Request.AnuncioRoupasRequest.Anunciar anuncio)
 {
     try
     {
         Models.TbAnuncio anu1 = conversorAnuncio.AnuncioParaTabela(anuncio);
         anu1.TbImagem = gerenciadorImagem.GerarMuitosNomes(anuncio.Imagens);
         Models.TbAnuncio resp = businessAnuncio.Anunciar(anu1);
         gerenciadorImagem.SalvarVariasImagens(anuncio.Imagens, resp.TbImagem.ToList());
         return(conversorAnuncio.AnuncioParaResponse(resp));
     }
     catch (System.Exception ex)
     {
         return(BadRequest(new Models.Response.Erro(400, ex.Message)));
     }
 }
Esempio n. 12
0
 public void Anunciar(Models.TbAnuncio anuncio)
 {
     ValidarTexto(anuncio.DsTitulo);
     ValidarData(anuncio.DtPublicacao);
     ValidarId(anuncio.IdUsuario);
     ValidarTexto(anuncio.TpProduto);
     ValidarTexto(anuncio.DsCep);
     ValidarTexto(anuncio.DsCidade);
     ValidarTexto(anuncio.DsCondicao);
     ValidarTexto(anuncio.DsEstado);
     ValidarTexto(anuncio.DsTamanho);
     ValidarTexto(anuncio.DsGenero);
     if (anuncio.DsCep.Length != 9)
     {
         throw new ArgumentException("CEP incorreto.");
     }
 }
Esempio n. 13
0
 public Models.TbAnuncio AlterarAnuncioParaTabela(Models.Request.AnuncioRoupasRequest.AlterarAnuncio anuncio)
 {
     Models.TbAnuncio resp = new Models.TbAnuncio();
     resp.NmMarca     = anuncio.Marca.Trim();
     resp.TpProduto   = anuncio.TipoDoProduto.Trim();
     resp.VlPreco     = anuncio.Preco;
     resp.DsCep       = anuncio.CEP.Trim();
     resp.DsCidade    = anuncio.Cidade.Trim();
     resp.DsCondicao  = anuncio.Condicao.Trim();
     resp.DsDescricao = anuncio.Descricao.Trim();
     resp.DsEstado    = anuncio.Estado.Trim();
     resp.DsGenero    = anuncio.Genero.Trim();
     resp.DsTamanho   = anuncio.Tamanho.Trim();
     resp.DsTitulo    = anuncio.Titulo.Trim();
     resp.IdUsuario   = anuncio.IdUsuario;
     resp.IdAnuncio   = anuncio.IdAnuncio;
     return(resp);
 }
Esempio n. 14
0
 public Models.TbImagem ApagarImagem(int IdImagem, int IdAnuncio)
 {
     validadores.ValidarId(IdImagem);
     validadores.ValidarId(IdAnuncio);
     Models.TbImagem imagem = databaseImagem.ConsultarImagem(IdImagem, IdAnuncio);
     if (imagem == null)
     {
         throw new ArgumentException("Imagem não encontrada, ou você não é o dono dessa imagem.");
     }
     Models.TbAnuncio anuncio = businessAnuncio.ConsultadoAnuncioDetalhado(IdAnuncio);
     if (anuncio.TbImagem.Count() <= 1)
     {
         Models.TbImagem a = new Models.TbImagem();
         a.ImgAnuncio = "semimagem.png";
         a.IdAnuncio  = IdAnuncio;
         databaseImagem.InserirImagem(a);
     }
     return(databaseImagem.ApagarImagem(IdImagem, IdAnuncio));
 }
Esempio n. 15
0
 public Models.TbAnuncio AlterarAnuncio(Models.TbAnuncio NovoAnuncio)
 {
     Models.TbAnuncio anuncio = ctx.TbAnuncio
                                .Include(x => x.TbImagem)
                                .First(x => x.IdAnuncio == NovoAnuncio.IdAnuncio && x.IdUsuario == NovoAnuncio.IdUsuario);
     anuncio.DsCep       = NovoAnuncio.DsCep;
     anuncio.DsCidade    = NovoAnuncio.DsCidade;
     anuncio.DsCondicao  = NovoAnuncio.DsCondicao;
     anuncio.DsDescricao = NovoAnuncio.DsDescricao;
     anuncio.DsEstado    = NovoAnuncio.DsEstado;
     anuncio.DsGenero    = NovoAnuncio.DsGenero;
     anuncio.DsTamanho   = NovoAnuncio.DsTamanho;
     anuncio.DsTitulo    = NovoAnuncio.DsTitulo;
     anuncio.NmMarca     = NovoAnuncio.NmMarca;
     anuncio.TpProduto   = NovoAnuncio.TpProduto;
     anuncio.VlPreco     = NovoAnuncio.VlPreco;
     ctx.SaveChanges();
     return(anuncio);
 }
Esempio n. 16
0
 public Models.Response.AnuncioRoupasResponse.Anuncio AnuncioParaResponse(Models.TbAnuncio anuncio)
 {
     Models.Response.AnuncioRoupasResponse.Anuncio resp = new Models.Response.AnuncioRoupasResponse.Anuncio();
     resp.Titulo         = anuncio.DsTitulo;
     resp.TipoProduto    = anuncio.TpProduto;
     resp.Tamanho        = anuncio.DsTamanho;
     resp.Preco          = anuncio.VlPreco;
     resp.Marca          = anuncio.NmMarca;
     resp.Condicao       = anuncio.DsCondicao;
     resp.DataPublicacao = anuncio.DtPublicacao;
     resp.Descricao      = anuncio.DsDescricao;
     resp.Genero         = anuncio.DsGenero;
     resp.IdAnuncio      = anuncio.IdAnuncio;
     resp.Imagens        = anuncio.TbImagem.Select(x => new Models.Response.AnuncioRoupasResponse.Imagem()
     {
         IdDoAnuncio = x.IdAnuncio,
         IdImagem    = x.IdImagem,
         TextoImagem = x.ImgAnuncio
     }).ToList();
     return(resp);
 }
Esempio n. 17
0
 public Models.TbAnuncio AnuncioParaTabela(Models.Request.AnuncioRoupasRequest.Anunciar anuncio)
 {
     Models.TbAnuncio resp = new Models.TbAnuncio();
     resp.IdUsuario          = anuncio.IdUsuario;
     resp.NmMarca            = anuncio.Marca.Trim();
     resp.TpProduto          = anuncio.TipoDoProduto.Trim();
     resp.VlPreco            = anuncio.Preco;
     resp.BtVendido          = false;
     resp.DsCep              = anuncio.CEP.Trim();
     resp.DsCidade           = anuncio.Cidade.Trim();
     resp.DsCondicao         = anuncio.Condicao.Trim();
     resp.DsDescricao        = anuncio.Descricao.Trim();
     resp.DsEstado           = anuncio.Estado.Trim();
     resp.DsGenero           = anuncio.Genero.Trim();
     resp.DsSituacao         = "Publicado";
     resp.DsTamanho          = anuncio.Tamanho.Trim();
     resp.DsTitulo           = anuncio.Titulo.Trim();
     resp.DtPublicacao       = DateTime.Now;
     resp.TbPerguntaResposta = new List <Models.TbPerguntaResposta>();
     resp.TbImagem           = new List <Models.TbImagem>();
     return(resp);
 }
Esempio n. 18
0
 public void InativarAnuncio(Models.TbAnuncio Anuncios)
 {
     ValidarTexto(Anuncios.DsSituacao);
 }
Esempio n. 19
0
 public Models.TbAnuncio Anunciar(Models.TbAnuncio anuncio)
 {
     ctx.Add(anuncio);
     ctx.SaveChanges();
     return(anuncio);
 }
Esempio n. 20
0
 public Models.TbAnuncio AlterarAnuncio(Models.TbAnuncio NovoAnuncio)
 {
     validadores.ValidarAlterarAnuncio(NovoAnuncio);
     Models.TbAnuncio resp = databaseAnuncio.ConsultarAnuncioDetalhado(NovoAnuncio.IdAnuncio);
     if (resp == null)
     {
         throw new ArgumentException("Você não é o dono desse anuncio.");
     }
     if (resp.IdUsuario != NovoAnuncio.IdUsuario)
     {
         throw new ArgumentException("Você não é o dono desse anuncio.");
     }
     if (NovoAnuncio.TbImagem.Count > 10)
     {
         throw new ArgumentException("Você só pode colocar 10 imagens no anuncio.");
     }
     if (NovoAnuncio.VlPreco <= 0)
     {
         throw new ArgumentException("O valor não pode ser 0 ou negativo");
     }
     if (NovoAnuncio.DsTitulo.Length > 100)
     {
         throw new ArgumentException("O título não pode ter mais de 100 caracteres.");
     }
     if (NovoAnuncio.DsDescricao.Length > 255)
     {
         throw new ArgumentException("A descrição não pode ter mais de 255 caracteres.");
     }
     if (NovoAnuncio.TpProduto.Length > 20)
     {
         throw new ArgumentException("O tipo do produto não pode ter mais de 20 caracteres.");
     }
     if (NovoAnuncio.NmMarca.Length > 70)
     {
         throw new ArgumentException("A marca não pode ter mais de 70 caracteres.");
     }
     if (NovoAnuncio.DsTamanho.Length > 50)
     {
         throw new ArgumentException("O tamanho não pode ter mais de 50 caracteres.");
     }
     if (NovoAnuncio.DsCidade.Length > 130)
     {
         throw new ArgumentException("A cidade não pode ter mais de 50 caracteres.");
     }
     if (NovoAnuncio.VlPreco > 100000000)
     {
         throw new ArgumentException("O preço tem que ser menor que 10 milhões.");
     }
     if (NovoAnuncio.NmMarca == "undefined" || NovoAnuncio.NmMarca == "")
     {
         NovoAnuncio.NmMarca = "Sem marca";
     }
     if (NovoAnuncio.DsDescricao == "undefined" || NovoAnuncio.DsDescricao == "")
     {
         NovoAnuncio.DsDescricao = "";
     }
     try
     {
         int cep = Convert.ToInt32(NovoAnuncio.DsCep.Replace("-", "").Replace(" ", ""));
     }
     catch (System.Exception)
     {
         throw new ArgumentException("CEP não pode ter letras nem simbolos.");
     }
     if (NovoAnuncio.DsCep.Contains(" "))
     {
         throw new ArgumentException("O CEP não pode ter espaços.");
     }
     resp = databaseAnuncio.AlterarAnuncio(NovoAnuncio);
     return(resp);
 }
Esempio n. 21
0
        public Models.Response.AnuncioRoupasResponse.AnuncioDetalhado AnuncioDetalhadoResponse(Models.TbAnuncio anuncio)
        {
            Models.Response.AnuncioRoupasResponse.AnuncioDetalhado resp = new Models.Response.AnuncioRoupasResponse.AnuncioDetalhado();
            resp.IdAnuncio       = anuncio.IdAnuncio;
            resp.IdDonoAnuncio   = anuncio.IdUsuario;
            resp.Titulo          = anuncio.DsTitulo;
            resp.Descricao       = anuncio.DsDescricao;
            resp.Produto         = anuncio.TpProduto;
            resp.Condicao        = anuncio.DsCondicao;
            resp.Genero          = anuncio.DsGenero;
            resp.Marca           = anuncio.NmMarca;
            resp.Tamanho         = anuncio.DsTamanho;
            resp.Preco           = anuncio.VlPreco;
            resp.Estado          = anuncio.DsEstado;
            resp.Cep             = anuncio.DsCep;
            resp.Vendido         = anuncio.BtVendido;
            resp.Situacao        = anuncio.DsSituacao;
            resp.Publicacao      = anuncio.DtPublicacao;
            resp.NomeVendedor    = anuncio.IdUsuarioNavigation.NmUsuario;
            resp.CelularVendedor = anuncio.IdUsuarioNavigation.DsCelular;
            resp.Email           = anuncio.IdUsuarioNavigation.DsEmail;
            resp.Cidade          = anuncio.DsCidade;

            resp.PerguntasERespotas = anuncio.TbPerguntaResposta.Select(x => new Models.Response.AnuncioRoupasResponse.PerguntaEResposta()
            {
                IdPerguntaResposta = x.IdPerguntaResposta,
                Pergunta           = x.DsPergunta,
                DataPergunta       = x.DtPergunta,
                Respondida         = x.BtRespondida,
                Resposta           = x.DsResposta,
                IdPerguntador      = x.IdPerguntador,
                IdRespondedor      = x.IdRespondedor,
                IdAnuncio          = x.IdAnuncio
            }).ToList();

            resp.Imagens = anuncio.TbImagem.Select(x => new Models.Response.AnuncioRoupasResponse.Imagem()
            {
                IdImagem    = x.IdImagem,
                IdDoAnuncio = x.IdAnuncio,
                TextoImagem = x.ImgAnuncio
            }).ToList();

            return(resp);
        }
Esempio n. 22
0
        public Models.Response.AnuncioRoupasResponse.AnuncioVendido ConversorAnuncioVendidoResponse(Models.TbAnuncio req)
        {
            Models.Response.AnuncioRoupasResponse.AnuncioVendido resp = new Models.Response.AnuncioRoupasResponse.AnuncioVendido();
            resp.IdAnuncio        = req.IdAnuncio;
            resp.IdUsuario        = req.IdUsuario;
            resp.Titulo           = req.DsTitulo;
            resp.Preco            = req.VlPreco;
            resp.Situacao         = req.DsSituacao;
            resp.DataDePublicacao = req.DtPublicacao;
            resp.Vendido          = req.BtVendido;

            return(resp);
        }