Esempio n. 1
0
 public static bool Save(Produto obj)
 {
     obj.dataCriacao = DateTime.Now;
     obj.dataEdicao  = DateTime.Now;
     try
     {
         if (obj.ID == 0)
         {
             using (var db = new WebPixContext())
             {
                 db.Produto.Add(obj);
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             using (var db = new WebPixContext())
             {
                 db.Produto.Update(obj);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 2
0
 public static int Save(Propiedades obj)
 {
     obj.dataCriacao = DateTime.Now;
     obj.dataEdicao  = DateTime.Now;
     try
     {
         if (obj.ID == 0)
         {
             using (var db = new WebPixContext())
             {
                 db.Propiedades.Add(obj);
                 db.SaveChanges();
             }
             return(obj.ID);
         }
         else
         {
             using (var db = new WebPixContext())
             {
                 db.Propiedades.Update(obj);
                 db.SaveChanges();
                 return(obj.ID);
             }
         }
     }
     catch (Exception e)
     {
         return(0);
     }
 }
Esempio n. 3
0
        public static bool SaveDept(List <Estrutura> departamento, int idUsuario, int idPropiedade, int idCliente)
        {
            foreach (Estrutura obj in departamento)
            {
                obj.dataCriacao = DateTime.Now;
                obj.dataEdicao  = DateTime.Now;
                try
                {
                    var query = String.Format(
                        @"insert into EstruturaXPropriedade   
                                    values({0}, {1}, '{2}', '{3}', {4}, {5},{6})",
                        obj.ID,
                        idPropiedade,
                        String.Format("{0:yyyy/MM/dd}", DateTime.Now),
                        String.Format("{0:yyyy/MM/dd}", DateTime.Now),
                        idUsuario,
                        idUsuario,
                        idCliente);


                    using (var db = new WebPixContext())
                    {
                        int noOfRowInserted = db.Database.ExecuteSqlCommand(query);
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(true);
        }
Esempio n. 4
0
 public static bool Save(UsuarioPermissao obj)
 {
     obj.DataCriacao   = DateTime.Now;
     obj.DateAlteracao = DateTime.Now;
     try
     {
         if (obj.ID == 0)
         {
             using (var db = new WebPixContext())
             {
                 db.UsuarioPermissao.Add(obj);
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             using (var db = new WebPixContext())
             {
                 db.UsuarioPermissao.Update(obj);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 5
0
 public static List <Produto> GetAll()
 {
     try
     {
         using (var db = new WebPixContext())
         {
             return(db.Produto.ToList());
         }
     }
     catch (Exception e)
     {
         ////
         return(new List <Produto>());
     }
 }
Esempio n. 6
0
 public static List <UsuarioPermissao> GetAll()
 {
     try
     {
         using (var db = new WebPixContext())
         {
             return(db.UsuarioPermissao.ToList());
         }
     }
     catch (Exception e)
     {
         ////
         return(new List <UsuarioPermissao>());
     }
 }
Esempio n. 7
0
        public async static Task <IEnumerable <Permissao> > GetByIdsAsync(IEnumerable <int> ids)
        {
            try
            {
                using (var db = new WebPixContext())
                {
                    var result = await db.Permissao.Where(p => ids.Contains(p.ID) && Convert.ToBoolean(p.VAdmin)).ToListAsync();

                    return(result);
                }
            }
            catch (Exception e)
            {
                return(new List <Permissao>());
            }
        }
Esempio n. 8
0
 public static bool Remove(Produto obj)
 {
     try
     {
         using (var db = new WebPixContext())
         {
             db.Produto.Remove(obj);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         ////
         return(false);
     }
 }
Esempio n. 9
0
        public async static Task <IEnumerable <Permissao> > GetByIdsAndMotor(IEnumerable <int> permissoesIDs, int idMotorAux)
        {
            try
            {
                using (var db = new WebPixContext())
                {
                    var result = await db.Permissao.Where(p => permissoesIDs.Contains(p.ID) &&
                                                          p.IdAux.Equals(idMotorAux)).ToListAsync();

                    return(result);
                }
            }
            catch (Exception e)
            {
                return(new List <Permissao>());
            }
        }
Esempio n. 10
0
        public static async Task <Permissao> CarregarPermissaoByUsuarioAsync(int idUsuario)
        {
            try
            {
                using (var db = new WebPixContext())
                {
                    var permissao = await db.Set <Permissao>().FromSql(@"
                            select a.* from Permissao a
                            inner join PermissaoXUsuario b on b.idUsuario = {0}
                            where a.id = b.idPermissao", idUsuario).FirstOrDefaultAsync();

                    return(permissao);
                }
            }
            catch (Exception e)
            {
                return(new Permissao());
            }
        }