Ejemplo n.º 1
0
        public bool Add(TaxpayerRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var taxpayer = new TbTipoContribuyente
                    {
                        Nombre = entity.Nombre,
                    };

                    db.TbTipoContribuyentes.Add(taxpayer);
                    if (db.SaveChanges() > 0)
                    {
                        result = true;
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al insertar los datos.");
            }
        }
Ejemplo n.º 2
0
        public TaxpayerRequest Select(int id)
        {
            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var taxpayer = db.TbTipoContribuyentes.Where(d => d.IdTipoContribuyente == id && d.Estato == true).FirstOrDefault();

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

                    return(new TaxpayerRequest
                    {
                        IdContribuyente = taxpayer.IdTipoContribuyente,
                        Nombre = taxpayer.Nombre,
                        Estado = taxpayer.Estato
                    });
                }
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener el dato.");
            }
        }
Ejemplo n.º 3
0
        public bool Delete(int id)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var taxpayer = db.TbTipoContribuyentes.Where(d => d.IdTipoContribuyente == id).FirstOrDefault();

                    if (taxpayer != null)
                    {
                        taxpayer.Estato = false;

                        db.Entry <TbTipoContribuyente>(taxpayer).State = EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            result = true;
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al eliminar los datos.");
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <TaxpayerRequest> Select()
        {
            List <TaxpayerRequest> lstTaxpayers = null;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    lstTaxpayers = (from d in db.TbTipoContribuyentes
                                    where d.Estato == true
                                    select new TaxpayerRequest
                    {
                        IdContribuyente = d.IdTipoContribuyente,
                        Nombre = d.Nombre,
                        Estado = d.Estato
                    }
                                    ).ToList();

                    return(lstTaxpayers);
                }
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener los datos.");
            }
        }
Ejemplo n.º 5
0
        public bool Update(TaxpayerRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var taxpayer = db.TbTipoContribuyentes.Where(d => d.IdTipoContribuyente == entity.IdContribuyente).FirstOrDefault();

                    if (taxpayer != null)
                    {
                        taxpayer.Nombre = entity.Nombre;

                        db.Entry <TbTipoContribuyente>(taxpayer).State = EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            result = true;
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al actualizar los datos.");
            }
        }
Ejemplo n.º 6
0
        public IEnumerable <DocumentRequest> Select()
        {
            List <DocumentRequest> lstDocuments = null;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    lstDocuments = (from d in db.TbTipoDocumentos
                                    where d.Estato == true
                                    select new DocumentRequest
                    {
                        IdTipoDoc = d.IdTipoDocumento,
                        Codigo = d.Codigo,
                        Nombre = d.Nombre,
                        Descripcion = d.Descripcion,
                        estado = d.Estato
                    }).ToList();
                }

                return(lstDocuments);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener los datos.");
            }
        }
Ejemplo n.º 7
0
        public bool Add(EntityRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var oentity = new TbEntidad
                    {
                        IdTipoDocumento     = entity.IdTipoDoc,
                        NroDocumento        = entity.NumDocumento,
                        RazonSocial         = entity.RazonSocial,
                        NombreComercial     = entity.NombreComercial,
                        IdTipoContribuyente = entity.IdContribuyente,
                        Direccion           = entity.Direccion,
                        Telefono            = entity.Telefono
                    };

                    db.TbEntidads.Add(oentity);
                    if (db.SaveChanges() > 0)
                    {
                        result = true;
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al insertar los datos.");
            }
        }
Ejemplo n.º 8
0
        public UserResponse Auht(AuthRequest entity)
        {
            var userResponse = new UserResponse();

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    // Encriptamos contraseña en Algoritmo SHA256
                    string password = Encrypt.GetSHA256(entity.Password);

                    // Buscamos usuario en bd
                    var user = db.TbUsuarios.Where(u => u.Email == entity.Email && u.Password == password).FirstOrDefault();

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

                    userResponse.IdUser = user.IdUsuario;
                    userResponse.Email  = user.Email;
                    userResponse.Token  = GenerateToken(user);
                }

                return(userResponse);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al iniciar sessión.");
            }
        }
Ejemplo n.º 9
0
        public bool Delete(int id)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var entity = db.TbEntidads.Where(d => d.IdEntidad == id).FirstOrDefault();

                    if (entity != null)
                    {
                        entity.Estato = false;

                        db.Entry <TbEntidad>(entity).State = EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            result = true;
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al eliminar los datos.");
            }
        }
Ejemplo n.º 10
0
        public EntityRequest Select(int id)
        {
            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var entity = db.TbEntidads.Where(d => d.IdEntidad == id && d.Estato == true).FirstOrDefault();

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

                    return(new EntityRequest
                    {
                        IdEntidad = entity.IdEntidad,
                        IdTipoDoc = entity.IdTipoDocumento,
                        NumDocumento = entity.NroDocumento,
                        RazonSocial = entity.RazonSocial,
                        NombreComercial = entity.NombreComercial,
                        IdContribuyente = entity.IdTipoContribuyente,
                        Direccion = entity.Direccion,
                        Telefono = entity.Telefono,
                        estado = entity.Estato
                    });
                }
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener el dato.");
            }
        }
Ejemplo n.º 11
0
        public bool Update(DocumentRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var document = db.TbTipoDocumentos.Where(d => d.IdTipoDocumento == entity.IdTipoDoc).FirstOrDefault();

                    if (document != null)
                    {
                        document.Codigo      = entity.Codigo;
                        document.Nombre      = entity.Nombre;
                        document.Descripcion = entity.Descripcion;

                        db.Entry <TbTipoDocumento>(document).State = EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            result = true;
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al actualizar los datos.");
            }
        }
Ejemplo n.º 12
0
        public bool Add(DocumentRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var document = new TbTipoDocumento
                    {
                        Codigo      = entity.Codigo,
                        Nombre      = entity.Nombre,
                        Descripcion = entity.Descripcion
                    };

                    db.TbTipoDocumentos.Add(document);
                    if (db.SaveChanges() > 0)
                    {
                        result = true;
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al insertar los datos.");
            }
        }
Ejemplo n.º 13
0
        public DocumentRequest Select(int id)
        {
            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var document = db.TbTipoDocumentos.Where(d => d.IdTipoDocumento == id && d.Estato == true).FirstOrDefault();

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

                    return(new DocumentRequest
                    {
                        IdTipoDoc = document.IdTipoDocumento,
                        Codigo = document.Codigo,
                        Nombre = document.Nombre,
                        Descripcion = document.Descripcion,
                        estado = document.Estato
                    });
                }
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener el dato.");
            }
        }
Ejemplo n.º 14
0
        public UserResponse SignUp(UserRequest entity)
        {
            var userResponse = new UserResponse();

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    string password = Encrypt.GetSHA256(entity.Password);

                    var user = new TbUsuario
                    {
                        Email    = entity.Email,
                        Password = password
                    };

                    db.TbUsuarios.Add(user);
                    db.SaveChanges();

                    userResponse.IdUser = user.IdUsuario;
                    userResponse.Email  = entity.Email;
                    userResponse.Token  = GenerateToken(user);
                }

                return(userResponse);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al registrar los datos.");
            }
        }
Ejemplo n.º 15
0
        public override bool IsValid(object value)
        {
            int id = (int)value;

            using (var db = new DB_CRUDContext())
            {
                if (db.TbTipoDocumentos.Find(id) == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 16
0
        public IEnumerable <EntityRequest> Select()
        {
            List <EntityRequest> lstEntitys = null;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    lstEntitys = (from e in db.TbEntidads
                                  join d in db.TbTipoDocumentos
                                  on e.IdTipoDocumento equals d.IdTipoDocumento
                                  join c in db.TbTipoContribuyentes
                                  on e.IdTipoContribuyente equals c.IdTipoContribuyente
                                  where e.Estato == true
                                  select new EntityRequest
                    {
                        IdEntidad = e.IdEntidad,
                        IdTipoDoc = d.IdTipoDocumento,
                        codigoDoc = d.Codigo,
                        NumDocumento = e.NroDocumento,
                        RazonSocial = e.RazonSocial,
                        NombreComercial = e.NombreComercial,
                        IdContribuyente = c.IdTipoContribuyente,
                        NombreContribuyente = c.Nombre,
                        Direccion = e.Direccion,
                        Telefono = e.Telefono,
                        estado = e.Estato
                    }).ToList();
                }

                return(lstEntitys);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al obtener los datos.");
            }
        }
Ejemplo n.º 17
0
        public bool Update(EntityRequest entity)
        {
            bool result = false;

            try
            {
                using (var db = new DB_CRUDContext())
                {
                    var oentity = db.TbEntidads.Where(d => d.IdEntidad == entity.IdEntidad).FirstOrDefault();

                    if (oentity != null)
                    {
                        oentity.IdTipoDocumento     = entity.IdTipoDoc;
                        oentity.NroDocumento        = entity.NumDocumento;
                        oentity.RazonSocial         = entity.RazonSocial;
                        oentity.NombreComercial     = entity.NombreComercial;
                        oentity.IdTipoContribuyente = entity.IdContribuyente;
                        oentity.Direccion           = entity.Direccion;
                        oentity.Telefono            = entity.Telefono;

                        db.Entry <TbEntidad>(oentity).State = EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            result = true;
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                throw new Exception("Ocurrio un error al insertar los datos.");
            }
        }