コード例 #1
0
 /// <summary>
 /// Kiểm tra và thêm mới User
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của User Mới Thêm Vào</returns>
 public static Int32 Add(UserEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return UserDAL.Add(entity);
 }
コード例 #2
0
 /// <summary>
 /// Kiểm tra và chỉnh sửa User
 /// </summary>
 /// <param name="entity">UserEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(UserEntity entity)
 {
     checkExist(entity.iUserID);
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return UserDAL.Edit(entity);
 }
コード例 #3
0
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">UserEntity:entity</param>
 private static void checkFK(UserEntity entity)
 {
     GroupEntity oGroup = GroupDAL.GetOne(entity.iGroupID);
     if (oGroup==null)
     {
         throw new Exception("Không tìm thấy :iGroupID");
     }
 }
コード例 #4
0
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">UserEntity: entity</param>
 private static void checkLogic(UserEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sUsername))
         throw new Exception(EX_SUSERNAME_EMPTY);
     if (String.IsNullOrEmpty(entity.sPassword))
         throw new Exception(EX_SPASSWORD_EMPTY);
     if (String.IsNullOrEmpty(entity.sEmail))
         throw new Exception(EX_SEMAIL_EMPTY);
     if (DateTime.Parse("1753-01-01")>entity.tLastVisit)
         throw new Exception(EX_TLASTVISIT_INVALID);
     if (entity.iGroupID < 0)
         throw new Exception(EX_IGROUPID_INVALID);
 }
コード例 #5
0
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">UserEntity: UserEntity</param>
 private static void checkDuplicate(UserEntity entity,bool checkPK)
 {
     List<UserEntity> list = UserDAL.GetAll();
     if (list.Exists(
         delegate(UserEntity oldEntity)
         {
             bool result =oldEntity.sUsername.Equals(entity.sUsername, StringComparison.OrdinalIgnoreCase);
             if(checkPK)
                 result=result && oldEntity.iUserID != entity.iUserID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_SUSERNAME_EXISTED);
     }
 }