public void Add(Brewery brewery) { using (var context = new MicrobrewitContext()) { brewery.Origin = null; brewery.CreatedDate = DateTime.Now; brewery.UpdatedDate = DateTime.Now; context.Entry(brewery).State = EntityState.Added; try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } }
public void Add(Yeast yeast) { using (var context = new MicrobrewitContext()) { if (yeast.Supplier != null) yeast.Supplier = null; context.Entry(yeast).State = EntityState.Added; try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } }
public virtual void Update(Other other) { using (var context = new MicrobrewitContext()) { context.Entry(other).State = EntityState.Modified; context.SaveChanges(); } }
public virtual void Update(Fermentable fermentable) { using (var context = new MicrobrewitContext()) { context.Entry(fermentable).State = EntityState.Modified; context.SaveChanges(); } }
public static void InsertDataDatabase() { using (var context = new MicrobrewitContext()) { var insert = File.ReadAllText(@"..\..\JSON\insert.sql"); context.Database.ExecuteSqlCommand(insert); } }
public static void DeleteDataInDatabase() { using(var context = new MicrobrewitContext()) { var delete = File.ReadAllText(@"..\..\JSON\delete.sql"); context.Database.ExecuteSqlCommand(delete); } }
public virtual void Update(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).State = EntityState.Modified; context.SaveChanges(); } }
public Hop GetSingle(int id, params string[] navigationProperties) { using (var context = new MicrobrewitContext()) { IQueryable<Hop> dbQueryable = context.Set<Hop>(); dbQueryable = navigationProperties.Aggregate(dbQueryable, (current, navigationProperty) => current.Include(navigationProperty)); return dbQueryable.SingleOrDefault(h => h.HopId == id); } }
public async Task<IList<Hop>> GetAllAsync(params string[] navigationProperties) { using (var context = new MicrobrewitContext()) { IQueryable<Hop> dbQueryable = context.Set<Hop>(); dbQueryable = navigationProperties.Aggregate(dbQueryable, (current, navigationProperty) => current.Include(navigationProperty)); return await dbQueryable.ToListAsync(); } }
public void Remove(Hop hop) { using (var context = new MicrobrewitContext()) { var dbHop = context.Hops.SingleOrDefault(h => h.HopId == hop.HopId); if(dbHop == null) throw new DbUpdateException("Hop does not exist."); context.Hops.Remove(dbHop); context.SaveChanges(); } }
public void Init() { TestUtil.DeleteDataInDatabase(); TestUtil.InsertDataDatabase(); AutoMapperConfiguration.Configure(); _context = new MicrobrewitContext(); _repository = new SupplierRepository(); _supplierElasticsearch = new SupplierElasticsearch(); _supplierService = new SupplierService(_repository,_supplierElasticsearch); _controller = new SupplierController(_supplierService); }
public void Init() { TestUtil.DeleteDataInDatabase(); TestUtil.InsertDataDatabase(); AutoMapperConfiguration.Configure(); _originElasticsearch = new OriginElasticsearch(); _context = new MicrobrewitContext(); _repository = new OriginRepository(); _originService = new OriginService(_originElasticsearch,_repository); _controller = new OriginController(_originService); }
public virtual void Update(Brewery brewery) { using (var context = new MicrobrewitContext()) { brewery.UpdatedDate = DateTime.Now; var originalBrewery = context.Breweries.Include(b => b.Members).SingleOrDefault(b => b.BreweryId == brewery.BreweryId); if (originalBrewery == null) return; brewery.CreatedDate = originalBrewery.CreatedDate; SetChanges(context, originalBrewery, brewery); foreach (var member in brewery.Members) { var existingMember = originalBrewery.Members.Any(m => m.MemberUsername.Equals(member.MemberUsername)); if (existingMember) { var originalMember = originalBrewery.Members.SingleOrDefault(m => m.MemberUsername.Equals(member.MemberUsername)); SetChanges(context, originalMember, member); } else { context.BreweryMembers.Add(member); } } foreach (var brewerySocial in brewery.Socials) { var existingBrewerySocial = context.BrewerySocials.SingleOrDefault( s => s.BreweryId == brewerySocial.BreweryId && s.SocialId == brewerySocial.SocialId); if (existingBrewerySocial != null) { SetChanges(context, existingBrewerySocial, brewerySocial); } else { context.BrewerySocials.Add(brewerySocial); } } brewery.Origin = null; try { context.SaveChanges(); } catch (Exception e) { throw; } } }
public void Init() { TestUtil.FlushRedisStore(); TestUtil.DeleteDataInDatabase(); TestUtil.InsertDataDatabase(); AutoMapperConfiguration.Configure(); _context = new MicrobrewitContext(); _repository = new HopRepository(); _elasticsearch = new HopElasticsearch(); _service = new HopService(_repository,_elasticsearch); _controller = new HopController(_service); }
public void Init() { TestUtil.FlushRedisStore(); TestUtil.DeleteDataInDatabase(); TestUtil.InsertDataDatabase(); AutoMapperConfiguration.Configure(); _context = new MicrobrewitContext(); _repository = new YeastRepository(); _yeastElasticsearch = new YeastElasticsearch(); _yeastService = new YeastService(_repository,_yeastElasticsearch); _controller = new YeastController(_yeastService); _node = new Uri("http://localhost:9200"); _settings = new ConnectionSettings(_node, defaultIndex: Setting.ElasticSearchIndex); _client = new ElasticClient(_settings); }
public void Add(Hop hop) { using (var context = new MicrobrewitContext()) { if (hop.OriginId > 0) { hop.Origin = null; } foreach (var subs in hop.Substituts) { context.Entry(subs).State = EntityState.Unchanged; } context.Hops.Add(hop); context.SaveChanges(); } }
public BeerStyle GetSingle(int id, params string[] navigationProperties) { BeerStyle item = null; using (var context = new MicrobrewitContext()) { IQueryable<BeerStyle> dbQuery = context.Set<BeerStyle>(); //Apply eager loading foreach (string navigationProperty in navigationProperties) dbQuery = dbQuery.Include<BeerStyle>(navigationProperty); item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(s => s.BeerStyleId == id); //Apply where clause } return item; }
public IList<BeerStyle> GetAll(params string[] navigationProperties) { List<BeerStyle> list; using (var context = new MicrobrewitContext()) { IQueryable<BeerStyle> dbQuery = context.Set<BeerStyle>(); //Apply eager loading foreach (string navigationProperty in navigationProperties) dbQuery = dbQuery.Include<BeerStyle>(navigationProperty); list = dbQuery .AsNoTracking() .ToList<BeerStyle>(); } return list; }
public virtual async Task RemoveAsync(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).State = EntityState.Deleted; try { await context.SaveChangesAsync(); } catch (Exception e) { Log.Debug(e); throw; } } }
public virtual async Task<int> UpdateAsync(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).State = EntityState.Modified; try { return await context.SaveChangesAsync(); } catch (Exception e) { throw; } } }
public virtual async Task AddAsync(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).State = EntityState.Added; try { await context.SaveChangesAsync(); } catch (DbEntityValidationException dbEx) { //foreach (var validationErrors in dbEx.EntityValidationErrors) //{ // foreach (var validationError in validationErrors.ValidationErrors) // { // Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); // Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); // throw dbEx; // } //} throw; } catch (Exception ex) { throw; } } }
public async Task<IList<HopForm>> GetHopFormsAsync() { using(var context = new MicrobrewitContext()) { return await context.HopForms.ToListAsync(); } }
public async Task RemoveAsync(Hop hop) { using (var context = new MicrobrewitContext()) { var dbHop = context.Hops.SingleOrDefault(h => h.HopId == hop.HopId); if (dbHop == null) throw new DbUpdateException("Hop does not exist."); context.Entry(dbHop).CurrentValues.SetValues(hop); await context.SaveChangesAsync(); } }
public Flavour AddFlavour(string name) { using (var context = new MicrobrewitContext()) { var flavourId = (context.Flavours.Max(f => (int?)f.FlavourId) ?? 0) + 1; var flavour = new Flavour() { FlavourId = flavourId, Name = name }; context.Flavours.Add(flavour); context.SaveChanges(); return flavour; } }
public IList<BrewerySocial> GetBrewerySocials(int breweryId) { using (var context = new MicrobrewitContext()) { return context.BrewerySocials.Where(b => b.BreweryId == breweryId).ToList(); } }
public HopForm GetForm(int id) { using (var context = new MicrobrewitContext()) { return context.HopForms.SingleOrDefault(h => h.Id == id); } }
public virtual async Task<IList<BeerStyle>> GetAllAsync(int from, int size,params string[] navigationProperties) { using (var context = new MicrobrewitContext()) { IQueryable<BeerStyle> dbQuery = context.Set<BeerStyle>(); //Apply eager loading foreach (string navigationProperty in navigationProperties) { dbQuery = dbQuery.Include<BeerStyle>(navigationProperty); } return await dbQuery.ToListAsync(); } }
public virtual void Remove(Other other) { using (var context = new MicrobrewitContext()) { context.Entry(other).State = EntityState.Deleted; context.SaveChanges(); } }
public virtual async Task<BeerStyle> GetSingleAsync(int id, params string[] navigationProperties) { using (var context = new MicrobrewitContext()) { IQueryable<BeerStyle> dbQuery = context.Set<BeerStyle>(); //Apply eager loading dbQuery = navigationProperties.Aggregate(dbQuery, (current, navigationProperty) => current.Include<BeerStyle>(navigationProperty)); return await dbQuery.SingleOrDefaultAsync(s => s.BeerStyleId == id); } }
public IList<HopForm> GetHopForms() { using (var context = new MicrobrewitContext()) { return context.HopForms.ToList(); } }