Пример #1
0
        public void Edit_Normal_Conditions()
        {
            var repo   = new SchoolRepository();
            var school = new School("Scotland High School");

            repo.Add(school);
            school.Name = "South High School";
            repo.Edit(school);
            Assert.True(repo.GetAll().Last().Name == "South High School");
        }
Пример #2
0
 public void Edit_Name_Null()
 {
     Assert.Throws <ArgumentNullException>(() => {
         var repo   = new SchoolRepository();
         var school = new School("West High School");
         repo.Add(school);
         school.Name = null;
         repo.Edit(school);
     });
 }
Пример #3
0
 /// <summary>
 ///  创建学校单位集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">学校单位集合</param>
 /// <returns></returns>
 public bool EditCollection(ref ValidationErrors validationErrors, IQueryable <School> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return(this.Edit(ref validationErrors, entitys.FirstOrDefault()));
             }
             else if (count > 1)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Edit(db, entitys);
                     if (count == repository.Save(db))
                     {
                         transactionScope.Complete();
                         return(true);
                     }
                     else
                     {
                         Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }