/// <summary>
 /// Kiểm tra và thêm mới PollAnswer
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của PollAnswer Mới Thêm Vào</returns>
 public static Int32 Add(PollAnswerEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return PollAnswerDAL.Add(entity);
 }
 /// <summary>
 /// Kiểm tra và chỉnh sửa PollAnswer
 /// </summary>
 /// <param name="entity">PollAnswerEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(PollAnswerEntity entity)
 {
     checkExist(entity);
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return PollAnswerDAL.Edit(entity);
 }
 protected void lbtnRemove_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < lstbAnswer.Items.Count; i++)
     {
         if (lstbAnswer.Items[i].Selected)
         {
             PollAnswerEntity entity = new PollAnswerEntity();
             entity.iAnswerID = Convert.ToInt32(lstbAnswer.Items[i].Value);
             PollAnswerBRL.Remove(entity);
         }
     }
     NapListbox();
 }
 protected void lbtnAdd_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         try
         {
             if (Session["PollID"] != null)
             {
                 PollAnswerEntity entity = new PollAnswerEntity();
                 entity.iCount = 0;
                 entity.iPollID = Convert.ToInt32(Session["PollID"]);
                 entity.sAnswer = txtAdd.Text;
                 PollAnswerBRL.Add(entity);
                 NapListbox();
             }
         }
         catch (Exception ex)
         {
             Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=AnswerManager';</script>");
         }
     }
 }
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">PollAnswerEntity: entity</param>
 private static void checkLogic(PollAnswerEntity entity)
 {
     if (String.IsNullOrEmpty(entity.sAnswer))
         throw new Exception(EX_SANSWER_EMPTY);
     if (entity.iCount < 0)
         throw new Exception(EX_ICOUNT_INVALID);
     if (entity.iPollID < 0)
         throw new Exception(EX_IPOLLID_INVALID);
 }
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">PollAnswerEntity:entity</param>
 private static void checkFK(PollAnswerEntity entity)
 {
     PollEntity oPoll = PollDAL.GetOne(entity.iPollID);
     if (oPoll==null)
     {
         throw new Exception("Không tìm thấy bình chọn này");
     }
 }
 private static void checkExist(PollAnswerEntity entity)
 {
     PollAnswerEntity oPollAnswer=PollAnswerDAL.GetOne(entity.iAnswerID);
     if(oPollAnswer==null)
         throw new Exception(EX_NOT_EXIST);
 }
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">PollAnswerEntity: PollAnswerEntity</param>
 private static void checkDuplicate(PollAnswerEntity entity,bool CheckInsert)
 {
     List<PollAnswerEntity> list = PollAnswerDAL.GetAll();
     if (list.Exists(
         delegate(PollAnswerEntity oldEntity)
         {
             bool result= oldEntity.sAnswer.Equals(entity.sAnswer, StringComparison.OrdinalIgnoreCase) && oldEntity.iPollID==entity.iPollID;
             if (!CheckInsert)
                 result=result && oldEntity.iAnswerID != entity.iAnswerID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_ANSWER_EXISTED);
     }
 }
 /// <summary>
 /// Kiểm tra và xoá PollAnswer
 /// </summary>
 /// <param name="entity">PollAnswerEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Remove(PollAnswerEntity entity)
 {
     checkExist(entity);
     return PollAnswerDAL.Remove(entity.iAnswerID);
 }