public virtual void Remove(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).State = EntityState.Deleted; context.SaveChanges(); } }
public void Add(BeerStyle beerStyle) { using (var context = DapperHelper.GetConnection()) { context.Open(); using (var transaction = context.BeginTransaction()) { try { var beerStyleId = context.Query<int>("INSERT BeerStyles(Name,SuperStyleId,OGLow,OGHigh,FGLow,FGHigh,IBULow,IBUHigh,SRMLow,SRMHigh,ABVLow,ABVHigh,Comments) " + "VALUES(@Name,@SuperStyleId,@OGLow,@OGHigh,@FGLow,@FGHigh,@IBULow,@IBUHigh,@SRMLow,@SRMHigh,@ABVLow,@ABVHigh,@Comments);" + "SELECT CAST(SCOPE_IDENTITY() as int);", new { beerStyle.Name, beerStyle.SuperStyleId, beerStyle.OGLow, beerStyle.OGHigh, beerStyle.FGLow, beerStyle.FGHigh, beerStyle.IBULow, beerStyle.IBUHigh, beerStyle.SRMLow, beerStyle.SRMHigh, beerStyle.ABVLow, beerStyle.ABVHigh, beerStyle.Comments, }, transaction); beerStyle.BeerStyleId = beerStyleId.SingleOrDefault(); transaction.Commit(); } catch (Exception e) { Log.Error(e.ToString()); transaction.Rollback(); throw; } } } }
public void Add(BeerStyle beerStyle) { using (var context = new MicrobrewitContext()) { context.Entry(beerStyle).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 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 void Update(BeerStyle beerStyle) { using (var context = DapperHelper.GetConnection()) { context.Open(); using (var transaction = context.BeginTransaction()) { try { context.Execute("UPDATE BeerStyles set Name = @Name,SuperStyleId = @SuperStyleId,OGLow = @OGLow,OGHigh = @OGHigh," + "FGLow = @FGLow,FGHigh = @FGHigh,IBULow = @IBULow,IBUHigh = @IBUHigh, SRMLow = @SRMLow, SRMHigh = @SRMHigh," + "ABVLow = @ABVLow, ABVHigh = @ABVHigh, Comments = @Comments " + "WHERE BeerStyleId = @BeerStyleId", new { beerStyle.BeerStyleId, beerStyle.Name, beerStyle.SuperStyleId, beerStyle.OGLow, beerStyle.OGHigh, beerStyle.FGLow, beerStyle.FGHigh, beerStyle.IBULow, beerStyle.IBUHigh, beerStyle.SRMLow, beerStyle.SRMHigh, beerStyle.ABVLow, beerStyle.ABVHigh, beerStyle.Comments, }, transaction); transaction.Commit(); } catch (Exception e) { Log.Error(e.ToString()); transaction.Rollback(); throw; } } } }
public async Task RemoveAsync(BeerStyle beerStyle) { using (var context = DapperHelper.GetConnection()) { context.Open(); using (var transaction = context.BeginTransaction()) { try { await context.ExecuteAsync("DELETE FROM BeerStyles WHERE BeerStyleId = @BeerStyleId", new { beerStyle.BeerStyleId }, transaction); transaction.Commit(); } catch (Exception e) { Log.Error(e.ToString()); transaction.Rollback(); throw; } } } }
public async Task AddAsync_Gets_Added() { var newBeerStyle = new BeerStyle { Name = "Test BeerStyle", ABVHigh = 1, ABVLow = 5, IBUHigh = 1, IBULow = 1, SRMHigh = 5, SRMLow = 3, OGLow = 1.001, OGHigh = 1.003, FGLow = 1.004, FGHigh = 1.005, Comments = "Notes", SuperStyleId = 1 }; await _beerStyleRepository.AddAsync(newBeerStyle); var beerStyle = await _beerStyleRepository.GetSingleAsync(newBeerStyle.BeerStyleId); Assert.NotNull(beerStyle); }