コード例 #1
0
 public List <Fornecedor> List()
 {
     using (var db = new ServicosContext())
     {
         return(db.Fornecedor.ToList());
     }
 }
コード例 #2
0
 public void Update(Fornecedor fornecedor)
 {
     try
     {
         using (var db = new ServicosContext())
         {
             var context = new ValidationContext(fornecedor, serviceProvider: null, items: null);
             var results = new List <ValidationResult>();
             if (Validator.TryValidateObject(fornecedor, context, results, true))
             {
                 db.Entry(fornecedor).State = EntityState.Modified;
                 db.SaveChanges();
                 return;
             }
             string erros = string.Empty;
             foreach (var item in results)
             {
                 erros += (string.IsNullOrEmpty(erros) ? "" : "\n") + item.ErrorMessage;
             }
             throw new DbEntityValidationException(erros);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #3
0
ファイル: ServicoRepository.cs プロジェクト: rafaasx/Servico
 public Servico Get(int id)
 {
     using (var db = new ServicosContext())
     {
         return(db.Servico.FirstOrDefault(x => x.Id == id));
     }
 }
コード例 #4
0
 public Fornecedor Get(int id)
 {
     using (var db = new ServicosContext())
     {
         return(db.Fornecedor.FirstOrDefault(x => x.Id == id));
     }
 }
コード例 #5
0
 public void CleanUp()
 {
     using (var db = new ServicosContext())
     {
         db.Database.ExecuteSqlCommand("DELETE from Fornecedor;");
         db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Fornecedor', RESEED, 0);");
     }
 }
コード例 #6
0
ファイル: ServicoRepository.cs プロジェクト: rafaasx/Servico
 public List <Servico> List()
 {
     using (var db = new ServicosContext())
     {
         return(db.Servico
                .Include(s => s.Cliente)
                .Include(s => s.Fornecedor)
                .ToList());
     }
 }
コード例 #7
0
 public void Delete(int id)
 {
     using (var db = new ServicosContext())
     {
         var fornecedor = db.Fornecedor.FirstOrDefault(x => x.Id == id);
         if (fornecedor != null)
         {
             db.Fornecedor.Remove(fornecedor);
             db.SaveChanges();
         }
         else
         {
             throw new DbEntityValidationException(string.Format("Não foi possível encontrar o fornecedor com código {0}", id));
         }
     }
 }
コード例 #8
0
 public void AddRange(List <Fornecedor> fornecedores)
 {
     using (var db = new ServicosContext())
     {
         var context = new ValidationContext(fornecedores, serviceProvider: null, items: null);
         var results = new List <ValidationResult>();
         if (Validator.TryValidateObject(fornecedores, context, results, true))
         {
             db.Fornecedor.AddRange(fornecedores);
             db.SaveChanges();
             return;
         }
         string erros = string.Empty;
         foreach (var item in results)
         {
             erros += (string.IsNullOrEmpty(erros) ? "" : "\n") + item.ErrorMessage;
         }
         throw new DbEntityValidationException(erros);
     }
 }
 public AbstractEditableEntityRepository(ServicosContext dbContext)
     : base(dbContext)
 {
 }
コード例 #10
0
 public PessoaRepo()
 {
     _contexto = new ServicosContext();
 }
コード例 #11
0
 public OrdemServicoRepo()
 {
     _contexto = new ServicosContext();
 }
コード例 #12
0
 public AbstractEntityRepository(ServicosContext dbContext)
 {
     _dbContext = dbContext;
 }