public void Add_OriginId_Gets_Set()
 {
     var newOrigin = new Origin { Name = "Ankh Morpork" };
     _originRespository.Add(newOrigin);
     var origin = _originRespository.GetSingle(newOrigin.OriginId);
     Assert.NotNull(origin);
 }
 public void Add_Gets_Added()
 {
     var origin = new Origin {Name = "Ankh Morpork"};
     _originRespository.Add(origin);
     var origins = _originRespository.GetAll();
     Assert.True(origins.Any(o => o.Name == origin.Name));
 }
 public virtual void Update(Origin origin)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(origin).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Remove_Gets_Removed()
 {
     var newOrigin = new Origin { Name = "Ankh Morpork" };
     _originRespository.Add(newOrigin);
     _originRespository.Remove(newOrigin);
     var origins = _originRespository.GetAll();
     Assert.True(origins.All(o => o.OriginId != newOrigin.OriginId));
 }
 public void Update(Origin origin)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             context.Execute(@"UPDATE Origins set Name = @Name WHERE OriginId = @OriginId", new {origin.Name, origin.OriginId},transaction);
             transaction.Commit();
         }
     }
 }
 public void Remove(Origin origin)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             context.Execute(@"DELETE FROM Origins WHERE OriginId = @OriginId;", new {origin.OriginId},
                 transaction);
             transaction.Commit();
         }
     }
 }
 public void Add(Origin origin)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             var originId = context.Query<int>(@"INSERT Origins(Name) VALUES(@Name); SELECT CAST(SCOPE_IDENTITY() as int)",new {origin.Name},transaction);
             origin.OriginId = originId.SingleOrDefault();
             transaction.Commit();
         }
     }
 }
 public void Add(Origin origin)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(origin).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 async Task<int> UpdateAsync(Origin origin)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             var result = await context.ExecuteAsync(@"UPDATE Origins set Name = @Name WHERE OriginId = @OriginId", new { origin.Name, origin.OriginId }, transaction);
             transaction.Commit();
             return result;
         }
     }
 }
 public virtual void Remove(Origin origin)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(origin).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
        public virtual async Task RemoveAsync(Origin origin)
        {
            using (var context = new MicrobrewitContext())
            {

                context.Entry(origin).State = EntityState.Deleted;
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Log.Debug(e);
                    throw;
                }
            }
        }
        public virtual async Task<int> UpdateAsync(Origin origin)
        {
            using (var context = new MicrobrewitContext())
            {
                context.Entry(origin).State = EntityState.Modified;
                try
                {
                    return await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    throw;
                }

            }
        }
        public virtual async Task AddAsync(Origin origin)
        {
            using (var context = new MicrobrewitContext())
            {
                context.Entry(origin).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;
                }
            }

        }