Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 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 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.º 7
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.º 8
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.º 9
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.");
            }
        }