/// <summary> /// Kiểm tra và thêm mới Baocaokhacphucloi /// </summary> /// <param name="entity">Entity</param> /// <returns>Int32: ID của Baocaokhacphucloi Mới Thêm Vào</returns> public static Int32 Add(BaocaokhacphucloiEntity entity) { checkLogic(entity); checkDuplicate(entity, false); checkFK(entity); return BaocaokhacphucloiDAL.Add(entity); }
/// <summary> /// Kiểm tra và chỉnh sửa Baocaokhacphucloi /// </summary> /// <param name="entity">BaocaokhacphucloiEntity</param> /// <returns>bool:kết quả thực hiện</returns> public static bool Edit(BaocaokhacphucloiEntity entity) { checkExist(entity.PK_iBaocaokhacphucloiID); checkLogic(entity); checkDuplicate(entity, true); checkFK(entity); return BaocaokhacphucloiDAL.Edit(entity); }
void taoBaocaokhacphucloi() { BaocaokhacphucloiEntity oBaocaokhacphucloi = new BaocaokhacphucloiEntity(); oBaocaokhacphucloi.dNgaykiemtra = DateTime.Today; int iUserID = Convert.ToInt32(Session["userID"].ToString()); oBaocaokhacphucloi.FK_iCosonuoiID = CosonuoitrongBRL.GetByFK_iUserID(iUserID)[0].PK_iCosonuoitrongID; oBaocaokhacphucloi.sDoankiemtra = ""; oBaocaokhacphucloi.sTailieukiemtheo = ""; }
/// <summary> /// Kiểm tra logic Entity /// </summary> /// <param name="entity">BaocaokhacphucloiEntity: entity</param> private static void checkLogic(BaocaokhacphucloiEntity entity) { if (entity.FK_iCosonuoiID < 0) throw new Exception(EX_FK_ICOSONUOIID_INVALID); if (DateTime.Parse("1753-01-01")>entity.dNgaykiemtra) throw new Exception(EX_DNGAYKIEMTRA_INVALID); }
/// <summary> /// Kiểm tra tồn tại khóa ngoại /// </summary> /// <param name="entity">BaocaokhacphucloiEntity:entity</param> private static void checkFK(BaocaokhacphucloiEntity entity) { CosonuoitrongEntity oCosonuoitrong = CosonuoitrongDAL.GetOne(entity.FK_iCosonuoiID); if (oCosonuoitrong==null) { throw new Exception("Không tìm thấy :FK_iCosonuoiID"); } }
/// <summary> /// Kiểm tra trùng lặp bản ghi /// </summary> /// <param name="entity">BaocaokhacphucloiEntity: BaocaokhacphucloiEntity</param> private static void checkDuplicate(BaocaokhacphucloiEntity entity,bool checkPK) { /* Example List<BaocaokhacphucloiEntity> list = BaocaokhacphucloiDAL.GetAll(); if (list.Exists( delegate(BaocaokhacphucloiEntity oldEntity) { bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase); if(checkPK) result=result && oldEntity.PK_iBaocaokhacphucloiID != entity.PK_iBaocaokhacphucloiID; return result; } )) { list.Clear(); throw new Exception(EX_FIELD_EXISTED); } */ }