コード例 #1
0
 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));
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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();
     }
 }
コード例 #6
0
 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;
             }
         }
     }
 }
コード例 #7
0
 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);
                 }
             }
         }
     }
 }
コード例 #9
0
        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();
                    }
                }
            }
        }
コード例 #10
0
 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));
 }
コード例 #11
0
 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;
                }
            }

        }