コード例 #1
0
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
 public virtual void Update(Yeast yeast)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(yeast).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #3
0
 public void Update(Yeast yeast)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute(
                  "UPDATE Yeasts set Name = @Name,TemperatureHigh = @TemperatureHigh,TemperatureLow = @TemperatureLow,Flocculation = @Flocculation," +
                  "AlcoholTolerance = @AlcoholTolerance,ProductCode = @ProductCode, Notes = @Notes, Type = @Type, BrewerySource = @BrewerySource, Species = @Species," +
                  "AttenutionRange = @AttenutionRange, PitchingFermentationNotes = @PitchingFermentationNotes, SupplierId = @SupplierId, Custom = @Custom " +
                  "WHERE YeastId = @YeastId;",
                  new
                  {
                      yeast.YeastId,
                      yeast.Name,
                      yeast.TemperatureHigh,
                      yeast.TemperatureLow,
                      yeast.Flocculation,
                      yeast.AlcoholTolerance,
                      yeast.ProductCode,
                      yeast.Notes,
                      yeast.Type,
                      yeast.BrewerySource,
                      yeast.Species,
                      yeast.AttenutionRange,
                      yeast.PitchingFermentationNotes,
                      yeast.SupplierId,
                      yeast.Custom
                  }, transaction);
                 transaction.Commit();
             }
             catch (Exception exception)
             {
                 Log.Error(exception.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
コード例 #4
0
 public void Add(Yeast yeast)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                var yeastId = context.Query<int>("INSERT Yeasts(Name,TemperatureHigh,TemperatureLow,Flocculation,AlcoholTolerance,ProductCode,Notes,Type,BrewerySource,Species,AttenutionRange,PitchingFermentationNotes,SupplierId,Custom) " +
                                                 "VALUES(@Name,@TemperatureHigh,@TemperatureLow,@Flocculation,@AlcoholTolerance,@ProductCode,@Notes,@Type,@BrewerySource,@Species,@AttenutionRange,@PitchingFermentationNotes,@SupplierId,@Custom); SELECT CAST(SCOPE_IDENTITY() as int);",
                     new
                     {
                        yeast.Name, 
                        yeast.TemperatureHigh, 
                        yeast.TemperatureLow, 
                        yeast.Flocculation, 
                        yeast.AlcoholTolerance, 
                        yeast.ProductCode, 
                        yeast.Notes, 
                        yeast.Type, 
                        yeast.BrewerySource, 
                        yeast.Species, 
                        yeast.AttenutionRange, 
                        yeast.PitchingFermentationNotes, 
                        yeast.SupplierId, 
                        yeast.Custom
                     }, transaction);
                 yeast.YeastId = yeastId.SingleOrDefault();
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Log.Error(e.ToString());
                 transaction.Rollback();
             }
         }
     }
 }
コード例 #5
0
 public async Task AddAsync_Gets_Added()
 {
     var newYeast = new Yeast { Name = "newYeast" + DateTime.Now.Ticks, ProductCode = "AAA", Type = "Liquid", Custom = true };
     await _yeastRepository.AddAsync(newYeast);
     var yeasts = await _yeastRepository.GetAllAsync();
     Assert.True(yeasts.Any(o => o.Name == newYeast.Name));
 }
コード例 #6
0
 public void Add_Gets_Added()
 {
     var newYeast = new Yeast {Name = "newYeast" + DateTime.Now.Ticks,ProductCode = "AAA" ,Type = "Liquid", Custom = true};
     _yeastRepository.Add(newYeast);
     var yeasts = _yeastRepository.GetAll();
     Assert.True(yeasts.Any(o => o.Name == newYeast.Name));
 }
コード例 #7
0
 public void Remove_Gets_Removed()
 {
     var newYeast = new Yeast { Name = "newYeast" + DateTime.Now.Ticks, ProductCode = "AAA", Type = "Liquid", Custom = true };
     _yeastRepository.Add(newYeast);
     _yeastRepository.Remove(newYeast);
     var yeasts = _yeastRepository.GetAll();
     Assert.True(yeasts.All(o => o.YeastId != newYeast.YeastId));
 }
コード例 #8
0
 public void Add_YeastId_Gets_Set()
 {
     var newYeast = new Yeast { Name = "newYeast" + DateTime.Now.Ticks, ProductCode = "AAA", Type = "Liquid", Custom = true };
     _yeastRepository.Add(newYeast);
     var yeast = _yeastRepository.GetSingle(newYeast.YeastId);
     Assert.NotNull(yeast);
 }
コード例 #9
0
 public virtual void Remove(Yeast yeast)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(yeast).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
コード例 #10
0
        public virtual async Task RemoveAsync(Yeast yeast)
        {
            using (var context = new MicrobrewitContext())
            {

                context.Entry(yeast).State = EntityState.Deleted;
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Log.Debug(e);
                    throw;
                }
            }
        }
コード例 #11
0
        public virtual async Task<int> UpdateAsync(Yeast yeast)
        {
            using (var context = new MicrobrewitContext())
            {
                context.Entry(yeast).State = EntityState.Modified;
                try
                {
                    return await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    throw;
                }

            }
        }
コード例 #12
0
        public virtual async Task AddAsync(Yeast yeast)
        {
            using (var context = new MicrobrewitContext())
            {
                if (yeast.Supplier != null)
                    yeast.Supplier = null;
                context.Entry(yeast).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;
                }
            }

        }
コード例 #13
0
 public async Task RemoveAsync(Yeast yeast)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 await context.ExecuteAsync("DELETE FROM Yeasts WHERE YeastId = @YeastId", new { yeast.YeastId }, transaction);
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Log.Error(e.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }