public async Task AddAsync_Gets_Added()
 {
     var newOther = new Other { Name = "newOther" + DateTime.Now.Ticks, Type = "Something", Custom = true };
     await _otherRepository.AddAsync(newOther);
     var others = await _otherRepository.GetAllAsync();
     Assert.True(others.Any(o => o.Name == newOther.Name));
 }
 public void Add_Hop_Id_Gets_Set()
 {
     var newOther = new Other { Name = "newOther" + DateTime.Now.Ticks, Type = "Something", Custom = true };
     _otherRepository.Add(newOther);
     var other = _otherRepository.GetSingle(newOther.OtherId);
     Assert.NotNull(other);
 }
 public void Add_Gets_Added()
 {
     var newOther = new Other {Name = "newOther" + DateTime.Now.Ticks, Type = "Something", Custom = true};
     _otherRepository.Add(newOther);
     var others = _otherRepository.GetAll();
     Assert.True(others.Any(o => o.Name == newOther.Name));
 }
예제 #4
0
 public virtual void Remove(Other other)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(other).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
예제 #5
0
 public virtual void Update(Other other)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(other).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Remove(Other other)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute("DELETE FROM Others WHERE OtherId = @OtherId", new {other.OtherId}, transaction);
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Log.Error(e.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
 public void Update(Other other)
 {
     using (var context = DapperHelper.GetConnection())
     {
         context.Open();
         using (var transaction = context.BeginTransaction())
         {
             try
             {
                 context.Execute("UPDATE Others set Name=@Name, Type=@Type, Custom=@Custom WHERE OtherId = @Id;",
                     new {other.Name, other.Type, other.Custom,Id = other.OtherId },transaction);
                 transaction.Commit();
             }
             catch (Exception exception)
             {
                 Log.Error(exception.ToString());
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
예제 #8
0
 public void Add(Other other)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(other).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(Other other)
        {
            using (var context = DapperHelper.GetConnection())
            {
                context.Open();
                using (var transaction = context.BeginTransaction())
                {

                    try
                    {
                       var otherId = context.Query<int>("INSERT Others(Name,Type,Custom) VALUES(@Name, @Type, @Custom); SELECT CAST(SCOPE_IDENTITY() as int)",
                            new {other.Name, other.Type, other.Custom},transaction);
                        other.OtherId = otherId.SingleOrDefault();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                        transaction.Rollback();
                    }
                }
            }
        }
 public async Task RemoveAsync_Gets_Removed()
 {
     var newOther = new Other { Name = "newOther" + DateTime.Now.Ticks, Type = "Something", Custom = true };
     await _otherRepository.AddAsync(newOther);
     await _otherRepository.RemoveAsync(newOther);
     var others = await _otherRepository.GetAllAsync();
     Assert.True(others.All(o => o.OtherId != newOther.OtherId));
 }
 public void Remove_Gets_Removed()
 {
     var newOther = new Other { Name = "newOther" + DateTime.Now.Ticks, Type = "Something", Custom = true };
     _otherRepository.Add(newOther);
     _otherRepository.Remove(newOther);
     var others = _otherRepository.GetAll();
     Assert.True(others.All(o => o.OtherId != newOther.OtherId));
 }
예제 #12
0
        public virtual async Task RemoveAsync(Other origin)
        {
            using (var context = new MicrobrewitContext())
            {

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

            }
        }
예제 #14
0
        public virtual async Task AddAsync(Other 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;
                }
            }

        }