Beispiel #1
0
        private tbEstado CastEstado(EstadoEntity estado)
        {
            tbEstado tb = new tbEstado();

            tb.sigla = estado.sigla;
            tb.nome  = estado.nome;

            return(tb);
        }
Beispiel #2
0
        public async Task <IActionResult> Create(EstadoEntity estadoEntity)
        {
            if (ModelState.IsValid)
            {
                await _estadoService.InsertAsync(estadoEntity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(estadoEntity));
        }
Beispiel #3
0
        public async Task <ActionResult <EstadoEntity> > PostEstadoEntity(EstadoEntity estadoEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _estadoService.InsertAsync(estadoEntity);

            return(Ok(estadoEntity));
        }
        protected void btnIncluir_Click(object sender, EventArgs e)
        {
            EstadoEntity estadoEntity = new EstadoEntity();
            string       retorno      = string.Empty;

            estadoEntity.sigla = txtSigla.Text;
            estadoEntity.nome  = txtNome.Text;

            retorno = estadoBusiness.InsereEstado(estadoEntity);
            CarregaGridView();
            Alert(retorno);
        }
Beispiel #5
0
        public async Task InsertAsync(EstadoEntity insertedEntity)
        {
            var uriPath = $"{_estadoHttpOptions.CurrentValue.EstadoPath}";

            //exemplo recomendado com a nova API: System.Net.Http.Json
            var httpResponseMessage = await _httpClient.PostAsJsonAsync(uriPath, insertedEntity);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                await _signInManager.SignOutAsync();
            }
        }
Beispiel #6
0
        public void Inserir_ValidEstado_DoesntThrowException()
        {
            var usuario = new EstadoEntity()
            {
                Sigla           = "MG",
                Nome            = "Minas Gerais",
                IdLoginCadastro = 1,
            };

            var codigo = new EstadoRepository().Inserir(usuario);

            Assert.IsTrue(codigo > 0);
        }
Beispiel #7
0
        public async Task UpdateAsync(EstadoEntity updatedEntity)
        {
            var pathWithId = $"{_estadoHttpOptions.CurrentValue.EstadoPath}/{updatedEntity.Id}";

            var httpContent = new StringContent(JsonConvert.SerializeObject(updatedEntity), Encoding.UTF8, "application/json");

            var httpResponseMessage = await _httpClient.PutAsync(pathWithId, httpContent);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                await _signInManager.SignOutAsync();
            }
        }
        public string InsereEstado(EstadoEntity Estado)
        {
            bool ret = lObjEstado.InsereEstado(Estado);

            if (ret)
            {
                return("Estado incluido com sucesso!");
            }
            else
            {
                return("Ocorreu um erro ao incluir o estado!");
            }
        }
Beispiel #9
0
        public async Task <IActionResult> Edit(int id, EstadoEntity estadoEntity)
        {
            if (id != estadoEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _estadoService.UpdateAsync(estadoEntity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(estadoEntity));
        }
Beispiel #10
0
        private List <EstadoEntity> CastListEstadoEntity(List <tbEstado> tbEstado)
        {
            List <EstadoEntity> lstEstado = new List <EstadoEntity>();

            foreach (var item in tbEstado)
            {
                EstadoEntity objEstado = new EstadoEntity();
                objEstado.sigla = item.sigla;
                objEstado.nome  = item.nome;

                lstEstado.Add(objEstado);
            }

            return(lstEstado);
        }
Beispiel #11
0
        //metodo auxiliar virtual=reescribible
        public virtual EstadoEntity GetEstadosFromReader(IDataReader reader)
        {
            EstadoEntity entity = null;

            try
            {
                entity        = new EstadoEntity();
                entity.Indice = reader["indice"] == System.DBNull.Value ? 0 : (int)reader["indice"];
                entity.Nombre = reader["nombre"] == System.DBNull.Value ? null : (String)reader["nombre"];
            }
            catch (Exception ex) {
                throw new Exception("Error converting data...", ex);
            }
            return(entity);
        }
Beispiel #12
0
        public bool InsereEstado(EstadoEntity Estado)
        {
            try
            {
                using (var context = new CirculoNegocioEntities())
                {
                    context.tbEstados.AddObject(CastEstado(Estado));
                    context.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #13
0
        public void CarregarBase_BaseIbge_DoesntThrowException()
        {
            string path = @"D:\Documents\Git\CostaAlmeidaCobranca\WebSite\js\estados_cidades.json";

            Root root;

            using (StreamReader r = new StreamReader(path))
            {
                string json = r.ReadToEnd();

                root = JsonConvert.DeserializeObject <Root>(json);
            }

            var estadoRepository = new EstadoRepository();
            var cidadeRepository = new CidadeRepository();

            using (var transation = new TransactionScope())
            {
                foreach (var estado in root.estados)
                {
                    var estadoEntity = new EstadoEntity()
                    {
                        IdLoginCadastro = 1,
                        Nome            = estado.nome,
                        Sigla           = estado.sigla
                    };

                    var idEstado = estadoRepository.Inserir(estadoEntity);

                    foreach (var cidade in estado.cidades)
                    {
                        var cidadeEntity = new CidadeEntity()
                        {
                            IdLoginCadastro = 1,
                            IdEstado        = idEstado,
                            Nome            = cidade
                        };

                        cidadeRepository.Inserir(cidadeEntity);
                    }
                }

                transation.Complete();
            }
        }
Beispiel #14
0
        public async Task <IActionResult> PutEstadoEntity(int id, EstadoEntity estadoEntity)
        {
            if (id != estadoEntity.Id)
            {
                return(BadRequest());
            }

            try
            {
                await _estadoService.UpdateAsync(estadoEntity);
            }
            catch (RepositoryException x)
            {
                ModelState.AddModelError(string.Empty, x.Message);
                return(BadRequest(ModelState));
            }

            return(NoContent());
        }
Beispiel #15
0
        public List <EstadoEntity> GetEstados()
        {
            var estadosDB = _estadoRepository.GetEstados();

            var estados = new List <EstadoEntity>();

            foreach (var estadoDB in estadosDB)
            {
                var estado = new EstadoEntity();
                estado.CodigoUf = estadoDB.CodigoUf;
                estado.Id       = estadoDB.Id;
                estado.Nome     = estadoDB.Nome;
                estado.Regiao   = estadoDB.Regiao;
                estado.Uf       = estadoDB.Uf;

                estados.Add(estado);
            }

            return(estados);
        }
Beispiel #16
0
        public List <EstadoEntity> ConsultaEstados()
        {
            MySqlCommand cmd = GetMySqlCommandInstance("Proc_GetEstados");

            List <EstadoEntity> retorno  = new List <EstadoEntity>();
            EstadoEntity        registro = null;

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    registro = new EstadoEntity
                    {
                        IdEstado    = (int)reader["idEstado"],
                        Descripcion = (string)reader["Descripcion"],
                    };
                    retorno.Add(registro);
                }
            }

            DisposeCommand(cmd);
            return(retorno);
        }
Beispiel #17
0
        public override List <EstadoEntity> GetEstados()
        {
            EstadoEntity        entityEstado = null;
            List <EstadoEntity> List         = new List <EstadoEntity>();

            SqlConnection connection = new SqlConnection(DataAccess.SqlGlobalConectionString);
            SqlCommand    command    = new SqlCommand("ConsultaEdos", connection);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = null;

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    entityEstado = new EstadoEntity();
                    entityEstado = GetEstadosFromReader(reader);
                    List.Add(entityEstado);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error al consultar Estados..." + ex.Message, ex);
            }
            finally
            {
                connection.Close();
                reader.Close();
                connection.Dispose();
            }
            return(List);
        }
Beispiel #18
0
        public List <OrdenEntity> ConsultaOrdenes(Filtro filtro)
        {
            using (OrdenData data = new OrdenData())
                using (EstadosData dataestados = new EstadosData())
                {
                    var ordenes = data.ConsultaOrdenes(filtro);
                    if (ordenes != null)
                    {
                        var          estados = dataestados.ConsultaEstados();
                        EstadoEntity estado  = null;
                        ordenes.ForEach(ord =>
                        {
                            estado = estados.FirstOrDefault(f => f.IdEstado == ord.Estado.IdEstado);
                            if (estado == null)
                            {
                                estado = new EstadoEntity();
                            }
                            ord.Estado.Comentario = estado.Descripcion;
                        });
                    }

                    return(ordenes);
                }
        }
 public int Insert(EstadoEntity t)
 {
     throw new NotImplementedException();
 }
Beispiel #20
0
 public async Task UpdateAsync(EstadoEntity updatedEntity)
 {
     await _estadoRepository.UpdateAsync(updatedEntity);
 }
Beispiel #21
0
 public async Task InsertAsync(EstadoEntity insertedEntity)
 {
     await _estadoRepository.InsertAsync(insertedEntity);
 }
 public void Update(EstadoEntity t)
 {
     throw new NotImplementedException();
 }