Exemplo n.º 1
0
        public void Eliminar(int id)
        {
            ProvinciaEntity entidad = new ProvinciaEntity();

            entidad.IdProvincia = id;
            EjecutarComando(daComun.TipoComandoEnum.Eliminar, entidad);
        }
Exemplo n.º 2
0
        public int Create(ProvinciaDto dto)
        {
            int result = default(int);

            try
            {
                string          key         = NormalizerKey.Normalize(dto.Nombre);
                ProvinciaEntity provinciaDb = _dbContext.ProvinciaDataSet.FirstOrDefault(x => x.Key == key);
                if (provinciaDb != null)
                {
                    return(result);
                }

                provinciaDb = MapDtoToEntity.Map(dto);
                _dbContext.ProvinciaDataSet.Add(provinciaDb);
                _dbContext.SaveChanges();

                result = provinciaDb.IdProvincia;
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var eve in ex.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        _logger.Error("ServiceProvincia.CreateOrUpdate", $"PropertyName: {ve.PropertyName} - ErrorMessage: {ve.ErrorMessage}", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("ServiceProvincia.Create", ex.Message, ex);
            }
            return(result);
        }
Exemplo n.º 3
0
        //Provincia
        public List <ProvinciaEntity> ListarProvincia_DAL(string vdepartamento)
        {
            List <ProvinciaEntity> listado = new List <ProvinciaEntity>();

            SqlCommand cmd = new SqlCommand("SP_VEH_ListarProvincia", cn.getcn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@idDepartamento", vdepartamento);

            cn.getcn.Open();

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                ProvinciaEntity clase = new ProvinciaEntity();
                clase.vprovincia   = dr["vprovincia"].ToString();
                clase.vdescripcion = dr["vdescripcion"].ToString();

                listado.Add(clase);
            }

            dr.Close();
            cmd.Dispose();
            cn.getcn.Close();

            return(listado);
        }
Exemplo n.º 4
0
        private ProvinciaEntity CrearEntidad(OdbcDataReader dr)
        {
            ProvinciaEntity entidad = new ProvinciaEntity();

            entidad.IdProvincia = Convert.ToInt32(dr["IdProvincia"]);
            entidad.Nombre      = dr["Nombre"].ToString();
            return(entidad);
        }
Exemplo n.º 5
0
        private void CrearParametros(OdbcCommand command, ProvinciaEntity entidad)
        {
            OdbcParameter parameter = null;

            parameter       = command.Parameters.Add("?", OdbcType.VarChar);
            parameter.Value = entidad.Nombre;

            parameter       = command.Parameters.Add("?", OdbcType.Int);
            parameter.Value = entidad.IdProvincia;
        }
Exemplo n.º 6
0
        public static ProvinciaEntity Map(ProvinciaDto entidadDto)
        {
            var entity = new ProvinciaEntity();

            entity.IdProvincia = entidadDto.Id;
            entity.Nombre      = entidadDto.Nombre;
            entity.Key         = entidadDto.Key;
            entity.Coordenadas = entidadDto.Coordenadas;
            entity.ZoomInicial = entidadDto.ZoomInicial;
            return(entity);
        }
        public static ProvinciaDto Map(ProvinciaEntity entity)
        {
            var entityDto = new ProvinciaDto();

            entityDto.Id          = entity.IdProvincia;
            entityDto.Nombre      = entity.Nombre;
            entityDto.Key         = entity.Key;
            entityDto.Coordenadas = entity.Coordenadas;
            entityDto.ZoomInicial = entity.ZoomInicial;
            return(entityDto);
        }
Exemplo n.º 8
0
        private void EjecutarComando(daComun.TipoComandoEnum sqlCommandType, ProvinciaEntity entidad)
        {
            OdbcConnection connection = null;
            OdbcCommand    command    = null;

            try {
                connection = (OdbcConnection)connectionDA.GetOpenedConnection();
                IDataParameter paramId = new OdbcParameter("?", OdbcType.Int);
                paramId.Value = entidad.IdProvincia;

                switch (sqlCommandType)
                {
                case daComun.TipoComandoEnum.Insertar:
                    command = new OdbcCommand(SQLInsert, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;

                case daComun.TipoComandoEnum.Actualizar:
                    command = new OdbcCommand(SQLUpdate, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;

                case daComun.TipoComandoEnum.Eliminar:
                    command = new OdbcCommand(SQLDelete, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;
                }

                command.ExecuteNonQuery();
                connection.Close();
            } catch (Exception ex) {
                throw new daException(ex);
            } finally {
                if (command != null)
                {
                    command.Dispose();
                }

                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Exemplo n.º 9
0
        public ProvinciaDto GetByKey(string key)
        {
            ProvinciaDto result = null;

            try
            {
                ProvinciaEntity provinciaDb = _dbContext.ProvinciaDataSet.FirstOrDefault(x => x.Key == key);
                if (provinciaDb != null)
                {
                    result = MapEntityToDto.Map(provinciaDb);
                }
            }
            catch (Exception ex)
            {
                _logger.Error("ServiceProvincia.GetByKey", ex.Message, ex);
            }
            return(result);
        }
Exemplo n.º 10
0
        public ProvinciaEntity ObtenerProvinciaPorId(int idprovincia)
        {
            OdbcConnection  connection = null;
            OdbcCommand     command    = null;
            OdbcDataReader  dr         = null;
            ProvinciaEntity provincia;

            try {
                connection = (OdbcConnection)connectionDA.GetOpenedConnection();
                command    = new OdbcCommand(SQLSearchByPrimaryKey, connection);
                command.Parameters.Add("?", OdbcType.Int);
                command.Parameters[0].Value = idprovincia;
                dr = command.ExecuteReader();

                provincia = new ProvinciaEntity();

                while (dr.Read())
                {
                    provincia = CrearEntidad(dr);
                }

                dr.Close();
                connection.Close();
            } catch (Exception ex) {
                throw new daException(ex);
            } finally {
                dr = null;

                if (command != null)
                {
                    command.Dispose();
                }

                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return(provincia);
        }
Exemplo n.º 11
0
 public void Actualizar(ProvinciaEntity entidad)
 {
     EjecutarComando(daComun.TipoComandoEnum.Actualizar, entidad);
 }
Exemplo n.º 12
0
 public void Insertar(ProvinciaEntity entidad)
 {
     EjecutarComando(daComun.TipoComandoEnum.Insertar, entidad);
 }