public void Add(Supplier supplier)
        {
            using (var context = new MicrobrewitContext())
            {
                if (supplier.Origin != null)
                    supplier.Origin = null;

                context.Entry(supplier).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(Supplier supplier)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(supplier).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Update(Supplier supplier)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute("UPDATE Suppliers set Name=@Name, OriginId=@OriginId WHERE SupplierId = @SupplierId;",
                     new {supplier.Name, supplier.OriginId,supplier.SupplierId},transaction);
                 transaction.Commit();
             }
             catch (Exception exception)
             {
                 Log.Error(exception.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
        public void Add(Supplier supplier)
        {
            using (var context = DapperHelper.GetConnection())
            {
                context.Open();
                using (var transaction = context.BeginTransaction())
                {

                    try
                    {
                       var supplierId = context.Query<int>("INSERT Suppliers(Name,OriginId) VALUES(@Name, @OriginId); SELECT CAST(SCOPE_IDENTITY() as int);",
                            new {supplier.Name,supplier.OriginId},transaction);
                        supplier.SupplierId = supplierId.SingleOrDefault();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                        transaction.Rollback();
                    }
                }
            }
        }
 public void Remove(Supplier supplier)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute("DELETE FROM Suppliers WHERE SupplierId = @SupplierId", new {supplier.SupplierId}, transaction);
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Log.Error(e.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
 public virtual void Remove(Supplier supplier)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(supplier).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
        public virtual async Task RemoveAsync(Supplier supplier)
        {
            using (var context = new MicrobrewitContext())
            {

                context.Entry(supplier).State = EntityState.Deleted;
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Log.Debug(e);
                    throw;
                }
            }
        }
        public virtual async Task AddAsync(Supplier supplier)
        {
            using (var context = new MicrobrewitContext())
            {
                if (supplier.Origin != null)
                    supplier.Origin = null;
                context.Entry(supplier).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 virtual async Task<int> UpdateAsync(Supplier supplier)
        {
            using (var context = new MicrobrewitContext())
            {
                context.Entry(supplier).State = EntityState.Modified;
                try
                {
                    return await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    throw;
                }

            }
        }
 public async Task AddAsync_Gets_Added()
 {
     var newSupplier = new Supplier { Name = "newSupplier" + DateTime.Now.Ticks};
     await _supplierRepository.AddAsync(newSupplier);
     var suppliers = await _supplierRepository.GetAllAsync();
     Assert.True(suppliers.Any(o => o.Name == newSupplier.Name));
 }
 public void Add_Gets_Added()
 {
     var newSupplier = new Supplier {Name = "newSupplier" + DateTime.Now.Ticks};
     _supplierRepository.Add(newSupplier);
     var suppliers = _supplierRepository.GetAll();
     Assert.True(suppliers.Any(o => o.Name == newSupplier.Name));
 }
 public async Task RemoveAsync_Gets_Removed()
 {
     var newSupplier = new Supplier { Name = "newSupplier" + DateTime.Now.Ticks};
     await _supplierRepository.AddAsync(newSupplier);
     await _supplierRepository.RemoveAsync(newSupplier);
     var suppliers = await _supplierRepository.GetAllAsync();
     Assert.True(suppliers.All(o => o.SupplierId != newSupplier.SupplierId));
 }
 public void Remove_Gets_Removed()
 {
     var newSupplier = new Supplier { Name = "newSupplier" + DateTime.Now.Ticks};
     _supplierRepository.Add(newSupplier);
     _supplierRepository.Remove(newSupplier);
     var suppliers = _supplierRepository.GetAll();
     Assert.True(suppliers.All(o => o.SupplierId != newSupplier.SupplierId));
 }
 public void Add_SupplierId_Gets_Set()
 {
     var newSupplier = new Supplier { Name = "newSupplier" + DateTime.Now.Ticks};
     _supplierRepository.Add(newSupplier);
     var supplier = _supplierRepository.GetSingle(newSupplier.SupplierId);
     Assert.NotNull(supplier);
 }