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; }
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; }
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; } }