Пример #1
0
 public Batch Create(Source source)
 {
     Batch batch;
     using (var dbContext = new TimberMillDbContext())
     {
         batch = new Batch {Source = source};
         dbContext.Batchs.Add(batch);
         dbContext.Entry(batch.Source).State = EntityState.Unchanged;
         dbContext.SaveChanges();
     }
     return batch;
 }
Пример #2
0
        public void Save(LogEvent logEvent)
        {
            using (var dbContext = new TimberMillDbContext())
            {
                dbContext.Batchs.Attach(logEvent.Batch);
                dbContext.Sources.Attach(logEvent.Batch.Source);

                dbContext.LogEvents.Add(logEvent);
                //dbContext.Entry(logEvent.Batch).State = EntityState.Unchanged;
                //dbContext.Entry(logEvent.Batch.Source).State = EntityState.Unchanged;
                dbContext.SaveChanges();
            }
        }
Пример #3
0
        public void Save(LogEvent logEvent)
        {
            using (var dbContext = new TimberMillDbContext())
            {
                dbContext.Batchs.Attach(logEvent.Batch);
                dbContext.Sources.Attach(logEvent.Batch.Source);

                dbContext.LogEvents.Add(logEvent);
                //dbContext.Entry(logEvent.Batch).State = EntityState.Unchanged;
                //dbContext.Entry(logEvent.Batch.Source).State = EntityState.Unchanged;
                dbContext.SaveChanges();
            }
        }
Пример #4
0
 public List<LogEvent> GetAll(Source source)
 {
     var events = new List<LogEvent>();
     using (var dbContext = new TimberMillDbContext())
     {
         events = dbContext
                     .LogEvents
                     .Include("Batch")
                     .Include("Batch.Source")
                     .Where(e => e.Batch.Source.Id == source.Id).ToList();
     }
     return events;
 }
Пример #5
0
        public List <LogEvent> GetAll(Source source)
        {
            var events = new List <LogEvent>();

            using (var dbContext = new TimberMillDbContext())
            {
                events = dbContext
                         .LogEvents
                         .Include("Batch")
                         .Include("Batch.Source")
                         .Where(e => e.Batch.Source.Id == source.Id).ToList();
            }
            return(events);
        }
Пример #6
0
        public Batch Create(Source source)
        {
            Batch batch;

            using (var dbContext = new TimberMillDbContext())
            {
                batch = new Batch {
                    Source = source
                };
                dbContext.Batchs.Add(batch);
                dbContext.Entry(batch.Source).State = EntityState.Unchanged;
                dbContext.SaveChanges();
            }
            return(batch);
        }
Пример #7
0
        public Source GetOrCreate(string name, string category)
        {
            using (var dbContext = new TimberMillDbContext())
            {
                var source = Get(dbContext, name, category);

                if (source == null)
                {
                    source = new Source {Name = name, Category = category};
                    dbContext.Sources.Add(source);
                    dbContext.SaveChanges();
                }
                return source;
            }
        }
Пример #8
0
        public Source GetOrCreate(string name, string category)
        {
            using (var dbContext = new TimberMillDbContext())
            {
                var source = Get(dbContext, name, category);

                if (source == null)
                {
                    source = new Source {
                        Name = name, Category = category
                    };
                    dbContext.Sources.Add(source);
                    dbContext.SaveChanges();
                }
                return(source);
            }
        }
Пример #9
0
 private Source Get(TimberMillDbContext dbContext, string name, string category)
 {
     return(dbContext.Sources.Where(s => s.Name == name && s.Category == category).FirstOrDefault());
 }
Пример #10
0
 private Source Get(TimberMillDbContext dbContext, string name, string category)
 {
     return dbContext.Sources.Where(s => s.Name == name && s.Category == category).FirstOrDefault();
 }