Пример #1
0
        public ActionResult Detalhes(Anunciante a)
        {
            string connectionString = "Server=DESKTOP-IO4T1DR\\SQLExpress; AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\DivulgueAquiDB.mdf; Database=DivulgueAquiDB; Trusted_Connection = Yes;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    string cmd = "SELECT * FROM Anunciante WHERE Email=@Email";

                    SqlCommand command = new SqlCommand(cmd, connection);
                    command.Connection.Open();
                    var reader             = command.ExecuteReader();
                    Models.Anunciante anun = new Models.Anunciante();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            anun.NomeAnunciante = (string)reader["NomeAnunciante"];
                            anun.NomeComercio   = (string)reader["NomeComercio"];
                            anun.TipoComercio   = (string)reader["TipoComercio"];
                            anun.TipoPacote     = (string)reader["TipoPacote"];
                            anun.IdAnunciante   = (int)reader["IdAnunciante"];
                            anun.Email          = (string)reader["Email"];
                            anun.Location       = (string)reader["Location"];
                        }
                    }
                    return(View(anun));
                }
                catch (Exception ex)
                {
                    throw new Exception("Erro: " + ex.Message);
                }
            }
        }
        public IHttpActionResult PutAnunciante(int id, Anunciante anunciante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != anunciante.IdAnunciante)
            {
                return(BadRequest());
            }

            db.Entry(anunciante).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnuncianteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Anunciante anunciante = db.Anunciantes.Find(id);

            db.Anunciantes.Remove(anunciante);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task Atualizar(Anunciante anunciante)
        {
            if (!ExecutarValidacao(new AnuncianteValidation(), anunciante))
            {
                return;
            }

            await _anuncianteRepository.Atualizar(anunciante);
        }
Пример #5
0
 private void Map(Anunciante cliente, ref Anunciante cl)
 {
     cl.Nome        = cliente.Nome;
     cl.Descricao   = cliente.Descricao;
     cl.Observacao  = cliente.Observacao;
     cl.CreatedById = cliente.CreatedById;
     cl.CreatedDate = cliente.CreatedDate;
     cl.UpdatedById = cliente.UpdatedById;
     cl.UpdateDate  = cliente.UpdateDate;
 }
Пример #6
0
 public ActionResult Editar([Bind(Include = "Id,Nome,Endereco,Telefone,Email,Descricao,CategoriaId,PlanoId,FotoId")] Anunciante anunciante)
 {
     if (ModelState.IsValid)
     {
         anuncianteRepository.Editar(anunciante);
         return(RedirectToAction("Lista"));
     }
     ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nome", anunciante.CategoriaId);
     ViewBag.PlanoId     = new SelectList(db.Planos, "Id", "Nome", anunciante.PlanoId);
     return(View(anunciante));
 }
Пример #7
0
 public ActionResult Edit([Bind(Include = "AnuncianteID,Nome,Cpf,Endereco,AnuncioID")] Anunciante anunciante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(anunciante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AnuncioID = new SelectList(db.Anuncios, "AnuncioID", "Titulo", anunciante.AnuncioID);
     return(View(anunciante));
 }
        public IHttpActionResult GetAnunciante(int id)
        {
            Anunciante anunciante = db.Anunciantes.Find(id);

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

            return(Ok(anunciante));
        }
        public IHttpActionResult PostAnunciante(Anunciante anunciante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Anunciantes.Add(anunciante);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = anunciante.IdAnunciante }, anunciante));
        }
 public ActionResult Edit([Bind(Include = "Id,Nome,Endereco,Telefone,Email,Descricao,CategoriaId,PlanoId")] Anunciante anunciante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(anunciante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nome", anunciante.CategoriaId);
     ViewBag.PlanoId     = new SelectList(db.Planos, "Id", "Nome", anunciante.PlanoId);
     return(View(anunciante));
 }
Пример #11
0
        public FileContentResult ObterImagem(int Id)
        {
            Anunciante anunciante = anuncianteRepository.ObterPorId(Id);

            if (anunciante.ArquivoFoto != null)
            {
                return(File(anunciante.ArquivoFoto, anunciante.MimeType));
            }
            else
            {
                return(null);
            }
        }
Пример #12
0
        public int Update(Anunciante anunciante)
        {
            var an = this.GetById(anunciante.Id);

            if (an == null)
            {
                throw new Exception($"Anunciante não encontrado: {anunciante.Id}");
            }

            this.Map(anunciante, ref an);
            an.UpdateDate = DateTime.Now;
            return(this._testersContext.SaveChanges());
        }
Пример #13
0
        // GET: Anunciantes/Details/5
        public ActionResult Detalhar(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Anunciante anunciante = anuncianteRepository.ObterPorId(id);

            if (anunciante == null)
            {
                return(HttpNotFound());
            }
            return(View(anunciante));
        }
        // GET: Anunciantes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Anunciante anunciante = db.Anunciantes.Find(id);

            if (anunciante == null)
            {
                return(HttpNotFound());
            }
            return(View(anunciante));
        }
Пример #15
0
        public Anunciante ObterPorId(Identidade id)
        {
            using (SqlConnection cn = new SqlConnection(StringDeConexao))
            {
                var select =
                    @"
                            SELECT [AnuncianteId]
                              ,[Nome]
                              ,[Sobrenome]
                              ,[Logradouro]
                              ,[Bairro]
                              ,[Cidade]
                              ,[Estado]
                              ,[Cep]
                              ,[Email]
                              ,[DDDTelefonePrincipal]
                              ,[TelefonePrincipal]
                              ,[DDDTelefoneComercial]
                              ,[TelefoneComercial]
                              ,[DDDCelular]
                              ,[Celular]
                            FROM [dbo].[Anunciante]
                            WHERE AnuncianteId = @id
                        ";

                var result = cn.QueryFirstOrDefault(select, new { id = id.ToString() });

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

                var nome = Nome.Novo(result.Nome, result.Sobrenome);

                var endereco = Endereco.Novo(result.Logradouro, result.Bairro,
                                             result.Cidade, result.Estado, result.Cep);

                var email = Email.Novo(result.Email);

                var contatos = AgendaTelefonica.Nova(
                    Telefone.Novo(result.DDDTelefonePrincipal, result.TelefonePrincipal),
                    Telefone.Novo(result.DDDTelefoneComercial, result.TelefoneComercial),
                    Telefone.Novo(result.DDDCelular, result.Celular));

                Anunciante anunciante = new Anunciante(new Identidade(Guid.Parse(result.AnuncianteId.ToString())),
                                                       nome, endereco, email, contatos);

                return(anunciante);
            }
        }
        public IHttpActionResult DeleteAnunciante(int id)
        {
            Anunciante anunciante = db.Anunciantes.Find(id);

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

            db.Anunciantes.Remove(anunciante);
            db.SaveChanges();

            return(Ok(anunciante));
        }
Пример #17
0
        // GET: Anunciantes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Anunciante anunciante = db.Anunciantes.Find(id);

            if (anunciante == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AnuncioID = new SelectList(db.Anuncios, "AnuncioID", "Titulo", anunciante.AnuncioID);
            return(View(anunciante));
        }
Пример #18
0
        private int InsertNovoAnunciante(AnuncianteModel anunciante, string userId)
        {
            var anc = new Anunciante()
            {
                Nome        = anunciante.Nome,
                CreatedById = userId,
                CreatedDate = DateTime.UtcNow,
                IsActive    = true,
                UpdateDate  = DateTime.UtcNow,
                UpdatedById = userId
            };

            this._testersContext.Anunciantes.Add(anc);
            this._testersContext.SaveChanges();
            return(anc.Id);
        }
        // GET: Anunciantes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Anunciante anunciante = db.Anunciantes.Find(id);

            if (anunciante == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nome", anunciante.CategoriaId);
            ViewBag.PlanoId     = new SelectList(db.Planos, "Id", "Nome", anunciante.PlanoId);
            return(View(anunciante));
        }
        public void PersistirUmNovoAnuncianteTest()
        {
            var identidade = Guid.NewGuid();
            var nome       = Nome.Novo("Gustavo", "Fontes");
            var endereco   = Endereco.Novo("Av. paulista", "Jardins", "São Paulo", "SP", 012345678);
            var email      = Email.Novo("*****@*****.**");

            var novoAnunciante = new Anunciante
                                 (
                identidade,
                nome,
                endereco,
                email,
                Telefone.Novo(11, "12345678"),
                Telefone.Novo(11, "12345678"),
                Telefone.Novo(11, "12345678"));

            _repositorio.Salvar(novoAnunciante);
        }
        public Guid InserirAnunciante()
        {
            var nome     = Nome.Novo("José Roberto", "Araújo");
            var endereco = Endereco.Novo("Rua do Paraíso", "Saúde", "São Paulo", "SP", 04123010);
            var email    = Email.Novo("*****@*****.**");
            var contatos = AgendaTelefonica.Nova(Telefone.Novo(11, "123456789"),
                                                 Telefone.Novo(11, "123456789"), Telefone.Novo(11, "123456789"));

            var id = new Identidade();

            var anunciante = new Anunciante(id, nome, endereco, email, contatos);

            _repositorio.Salvar(anunciante);

            var anuncianteResult = _repositorio.ObterPorId(id);

            Console.WriteLine(anuncianteResult.Nome);

            return(id.Id);
        }
Пример #22
0
        public ActionResult Editar(AnuncianteViewModel anunciante)
        {
            if (!ModelState.IsValid)
            {
                return(View(anunciante));
            }

            var anuncianteSalvar = new Anunciante
            {
                Id        = anunciante.Id,
                Nome      = anunciante.Nome,
                Telefone  = anunciante.Telefone,
                Email     = anunciante.Email,
                Descricao = anunciante.Descricao
            };

            anuncianteApp.Salvar(anuncianteSalvar);
            this.Flash("Anunciante Salvo com Sucesso!");
            return(RedirectToAction("Index"));
        }
        private List <string> getMeusAnuncios(Anunciante a)
        {
            List <string> lista            = new List <string>();
            string        connectionString = "Server=DESKTOP-IO4T1DR\\SQLExpress; AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\DivulgueAquiDB.mdf; Database=DivulgueAquiDB; Trusted_Connection = Yes;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string cmd = "SELECT ao.diretorio  FROM anuncios AS ao INNER JOIN  anunciante_anuncios AS aa ON (ao.id_anuncio =aa.id_anuncio) where aa.email=@Email;";
                using (SqlCommand command = new SqlCommand(cmd, connection)) {
                    command.Parameters.AddWithValue("@Email", a.Email);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        lista.Add((string)reader["diretorio"]);
                    }
                }
            }
            return(lista);
        }
        private void AtualizarQuantidade(Anunciante a)
        {
            string connectionString = "Server=DESKTOP-IO4T1DR\\SQLExpress; AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\DivulgueAquiDB.mdf; Database=DivulgueAquiDB; Trusted_Connection = Yes;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    string cmd = "UPDATE anunciante SET anunciosinseridosQtd=anunciosinseridosQtd+1 WHERE email=@Email;";

                    SqlCommand command = new SqlCommand(cmd, connection);
                    command.Parameters.AddWithValue("@Email", a.Email);
                    command.Connection.Open();
                }
                catch (Exception ex)
                {
                    throw new Exception("Erro: " + ex.Message);
                }
            }
        }
Пример #25
0
        public ActionResult Criar([Bind(Include = "Id,Nome,Endereco,Telefone,Email,Descricao,CategoriaId,PlanoId")] Anunciante anunciante, HttpPostedFileBase Imagem)
        {
            if (ModelState.IsValid)
            {
                if (Imagem != null)
                {
                    //informa qual o tipo do arquivo Array de bytes.
                    anunciante.MimeType = Imagem.ContentType;
                    //informa qual o tamanho do arquivo Array de bytes.
                    anunciante.ArquivoFoto = new byte[Imagem.ContentLength];
                    //Passar o arquivo carregado pelo usuário para o dentro do Array de bytes que foi criado.
                    Imagem.InputStream.Read(anunciante.ArquivoFoto, 0, Imagem.ContentLength);
                }
                anuncianteRepository.Adiciconar(anunciante);
                return(RedirectToAction("Lista"));
            }

            ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nome", anunciante.CategoriaId);
            ViewBag.PlanoId     = new SelectList(db.Planos, "Id", "Nome", anunciante.PlanoId);
            return(View(anunciante));
        }
Пример #26
0
        public void PersistirUmNovoAnuncianteTest()
        {
            var identidade       = Guid.NewGuid();
            var nome             = Nome.Novo("Gustavo", "Fontes");
            var endereco         = Endereco.Novo("Av. paulista", "Jardins", "São Paulo", "SP", 012345678);
            var email            = Email.Novo("*****@*****.**");
            var agendaTelefonica = AgendaTelefonica
                                   .Nova(
                Telefone.Novo(11, "12345678"),
                Telefone.Novo(11, "12345678"),
                Telefone.Novo(11, "123456789")
                );

            var novoAnunciante = new Anunciante(identidade, nome, endereco, email, agendaTelefonica);

            _repositorio.Salvar(novoAnunciante);

            var anunciante = _repositorio.ObterPor(identidade);

            anunciante.Should().NotBeNull();
        }
        private void SalvarCaminho(string path, Anunciante a)
        {
            string connectionString = "Server=DESKTOP-IO4T1DR\\SQLExpress; AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\DivulgueAquiDB.mdf; Database=DivulgueAquiDB; Trusted_Connection = Yes;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string cmd = "INSERT INTO Anuncio(diretorio) VALUES @Path";
                using (SqlCommand command = new SqlCommand(cmd, connection))
                {
                    command.Parameters.AddWithValue("@Path", path);
                    command.ExecuteNonQuery();
                }
                string cmd1 = "INSERT INTO Anunciante_Anuncios(email,id_anuncio) VALUES @Email,(SELECT id_anuncio FROM Anuncios WHERE diretorio=@Path)";
                using (SqlCommand command = new SqlCommand(cmd1, connection))
                {
                    command.Parameters.AddWithValue("@Path", a.Email);
                    command.Parameters.AddWithValue("@Path", path);
                    command.ExecuteNonQuery();
                }
            }
        }
Пример #28
0
        public ActionResult CadastroAnunciante(Anunciante a)
        {
            string connectionString = "Server=DESKTOP-IO4T1DR\\SQLExpress; AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\DivulgueAquiDB.mdf; Database=DivulgueAquiDB; Trusted_Connection = Yes;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    string cmd = "INSERT INTO Anunciante(nomeAnunciante,nomeComercio,email,tipoComercio,valorPacote,senha,anunciosinseridosQtd,latlong) VALUES @NomeAnunciante,@NomeComercio,@Email,@TipoComercio,@ValorPacote,@Senha,@AnunciosinseridosQtd,@LatLong,@Limite";

                    SqlCommand command = new SqlCommand(cmd, connection);
                    command.Parameters.AddWithValue("@NomeAnunciante", a.NomeAnunciante);
                    command.Parameters.AddWithValue("@NomeComercio", a.NomeComercio);
                    command.Parameters.AddWithValue("@Email", a.Email);
                    command.Parameters.AddWithValue("@TipoComercio", a.TipoComercio);
                    command.Parameters.AddWithValue("@ValorPacote", a.ValorPacote);
                    command.Parameters.AddWithValue("@Senha", a.Senha);
                    command.Parameters.AddWithValue("@AnunciosinseridosQtd ", 0);
                    command.Parameters.AddWithValue("@LatLong", a.LatLong);
                    if (a.ValorPacote == 9.90)
                    {
                        command.Parameters.AddWithValue("@Limite", 4);
                    }
                    if (a.ValorPacote == 19.90)
                    {
                        command.Parameters.AddWithValue("@Limite", 8);
                    }
                    if (a.ValorPacote == 39.90)
                    {
                        command.Parameters.AddWithValue("@Limite", 0);
                    }
                    command.Connection.Open();
                    return(View());
                }
                catch (Exception ex)
                {
                    throw new Exception("Erro: " + ex.Message);
                }
            }
        }
Пример #29
0
        public void Salvar(Anunciante agregado)
        {
            using (SqlConnection cn = new SqlConnection(StringDeConexao))
            {
                var insert =
                    @"
                            INSERT INTO ANUNCIANTE([AnuncianteId], [Nome],[Sobrenome],[Logradouro],[Bairro],[Cidade],[Estado]
                                ,[Cep],[Email],[DDDTelefonePrincipal],[TelefonePrincipal],[DDDTelefoneComercial]
                                ,[TelefoneComercial],[DDDCelular],[Celular])
                            VALUES(@anuncianteId, @nome, @sobreNome, @logradouro, @bairro, @cidade, @estado, @cep, @email,
                                   @dddTelefonePrincipal, @telefonePrincipal, @dddTelefoneComercial,
                                   @telefoneComercial, @dddCelular, @celular)
                        ";

                var parametros = new
                {
                    anuncianteId         = agregado.Id.ToString(),
                    nome                 = agregado.Nome.PrimeiroNome,
                    sobreNome            = agregado.Nome.Sobrenome,
                    logradouro           = agregado.Endereco.Logradouro,
                    bairro               = agregado.Endereco.Bairro,
                    cidade               = agregado.Endereco.Cidade,
                    estado               = agregado.Endereco.Estado,
                    cep                  = agregado.Endereco.Cep,
                    email                = agregado.Email.Valor,
                    dddTelefonePrincipal = agregado.AgendaTelefonica.TelefonePrincipal.DDD,
                    telefonePrincipal    = agregado.AgendaTelefonica.TelefonePrincipal.Numero,
                    dddTelefoneComercial = agregado.AgendaTelefonica.TelefoneComercial.DDD,
                    telefoneComercial    = agregado.AgendaTelefonica.TelefoneComercial.Numero,
                    dddCelular           = agregado.AgendaTelefonica.Celular.DDD,
                    celular              = agregado.AgendaTelefonica.Celular.Numero
                };

                cn.Open();
                cn.Execute(insert, parametros);
                cn.Close();
            }
        }
Пример #30
0
        private Anunciante DTOtoAnunciante(AnuncianteDTO a)
        {
            if (a == null)
            {
                return null;
            }

            Anunciante anunciante = new Anunciante();

            anunciante.Id = a.Id;
            anunciante.Nome = a.Nome;
            anunciante.Tipo = a.Tipo;
            anunciante.Inscricao = a.Inscricao;
            anunciante.Senha = a.Senha;
            anunciante.Email = a.Email;

            a.Telefones.ForEach(t =>
            {
                Telefone telefone = new Telefone();
                telefone.DDD = t.DDD;
                telefone.DDI = t.DDI;
                telefone.Id = t.Id;
                telefone.Numero = t.Numero;
                anunciante.IncluirTelefone(telefone);
            });

            a.Enderecos.ForEach(e =>
            {
                Endereco endereco = new Endereco();
                endereco.Bairro = e.Bairro;
                endereco.Cep = e.Cep;
                endereco.Cidade = e.Cidade;
                endereco.Complemento = e.Complemento;
                endereco.Estado = e.Estado;
                endereco.Id = e.Id;
                endereco.Logradouro = e.Logradouro;
                endereco.Numero = e.Numero;
                endereco.Pais = e.Pais;
                anunciante.IncluirEndereco(endereco);
            });

            return anunciante;
        }
Пример #31
0
        private AnuncianteDTO AnuncianteToDTO(Anunciante a)
        {
            if (a == null)
            {
                return null;
            }

            AnuncianteDTO anunciante = new AnuncianteDTO();

            anunciante.Id = a.Id;
            anunciante.Nome = a.Nome;
            anunciante.Tipo = a.Tipo;
            anunciante.Inscricao = a.Inscricao;
            anunciante.Senha = a.Senha;
            anunciante.Email = a.Email;
            anunciante.Telefones = new List<TelefoneDTO>();
            anunciante.Enderecos = new List<EnderecoDTO>();

            if (a.Telefones != null && a.Telefones.Count != 0)
            {
                a.Telefones.ForEach(t =>
                {
                    TelefoneDTO telefone = new TelefoneDTO();
                    telefone.DDD = t.DDD;
                    telefone.DDI = t.DDI;
                    telefone.Id = t.Id;
                    telefone.Numero = t.Numero;

                    anunciante.Telefones.Add(telefone);

                });
            }

            if (a.Enderecos != null && a.Enderecos.Count != 0)
            {
                a.Enderecos.ForEach(e =>
                {
                    EnderecoDTO endereco = new EnderecoDTO();
                    endereco.Bairro = e.Bairro;
                    endereco.Cep = e.Cep;
                    endereco.Cidade = e.Cidade;
                    endereco.Complemento = e.Complemento;
                    endereco.Estado = e.Estado;
                    endereco.Id = e.Id;
                    endereco.Logradouro = e.Logradouro;
                    endereco.Numero = e.Numero;
                    endereco.Pais = e.Pais;

                    anunciante.Enderecos.Add(endereco);
                });
            }
            return anunciante;
        }
Пример #32
0
 public void Salvar(Anunciante entidade)
 {
     contexto.Save(entidade);
 }