Ejemplo n.º 1
0
 /// <summary>
 /// Kiểm tra và thêm mới Faq
 /// </summary>
 /// <param name="entity">Entity</param>
 /// <returns>Int32: ID của Faq Mới Thêm Vào</returns>
 public static Int32 Add(FaqEntity entity)
 {
     checkLogic(entity);
     checkDuplicate(entity, false);
     checkFK(entity);
     return FaqDAL.Add(entity);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Kiểm tra và chỉnh sửa Faq
 /// </summary>
 /// <param name="entity">FaqEntity</param>
 /// <returns>bool:kết quả thực hiện</returns>
 public static bool Edit(FaqEntity entity)
 {
     checkExist(entity.PK_iFaqID);
     checkLogic(entity);
     checkDuplicate(entity, true);
     checkFK(entity);
     return FaqDAL.Edit(entity);
 }
        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
                {
                    if (Session["UserID"] == null)
                        Response.Redirect("~/");
                    FaqEntity oFAQ = new FaqEntity();
                    oFAQ.FK_iFaqCateID = Convert.ToInt32(ddlLoaiCauHoi.SelectedValue);
                    oFAQ.sQuestion = txtCauhoi.Text;
                    //
                    FaqAnswersEntity oFAQAnswer = new FaqAnswersEntity();
                    oFAQAnswer.sContent = txtCautraloi.Text;
                    //
                    if (Session["UserID"] != null)
                    {
                        int userID = Convert.ToInt32(Session["UserID"]);
                        oFAQ.FK_iUserID = userID;

                        if (btnOK.CommandName == "Edit")
                        {
                            int faqID = Convert.ToInt32(btnOK.CommandArgument);
                            int faqanswerID = Convert.ToInt32(btnReset.CommandArgument);
                            oFAQ.PK_iFaqID = faqID;
                            oFAQAnswer.PK_iFaqAnswerID = faqanswerID;
                            oFAQAnswer.FK_iFaqID = faqID;
                            FaqBRL.Edit(oFAQ);
                            FaqAnswersBRL.Edit(oFAQAnswer);
                            btnOK.CausesValidation = true;
                        }
                        else
                        {
                            int faqAddID = FaqBRL.Add(oFAQ);
                            oFAQAnswer.FK_iFaqID = faqAddID;
                            FaqAnswersBRL.Add(oFAQAnswer);
                        }
                        lblThongbao.Text = "Cập nhật thành công";
                        btnOK.Text = "Thêm";
                        //Nạp lại dữ liệu
                        pnEdit.Visible = false;
                        Response.Redirect(Request.Url.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<script language=\"javascript\">alert('" + ex.Message + "');location='Default.aspx?page=FAQManager';</script>");
                }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Kiểm tra logic Entity
 /// </summary>
 /// <param name="entity">FaqEntity: entity</param>
 private static void checkLogic(FaqEntity entity)
 {
     if (entity.FK_iFaqCateID < 0)
         throw new Exception(EX_FK_IFAQCATEID_INVALID);
     if (String.IsNullOrEmpty(entity.sQuestion))
         throw new Exception(EX_SQUESTION_EMPTY);
     if (DateTime.Parse("1753-01-01")>entity.dDate)
         throw new Exception(EX_DDATE_INVALID);
     if (entity.iViews < 0)
         throw new Exception(EX_IVIEWS_INVALID);
     if (entity.FK_iUserID < 0)
         throw new Exception(EX_FK_IUSERID_INVALID);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Kiểm tra tồn tại khóa ngoại
 /// </summary>
 /// <param name="entity">FaqEntity:entity</param>
 private static void checkFK(FaqEntity entity)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Kiểm tra trùng lặp bản ghi
 /// </summary>
 /// <param name="entity">FaqEntity: FaqEntity</param>
 private static void checkDuplicate(FaqEntity entity,bool checkPK)
 {
     /*
     Example
     List<FaqEntity> list = FaqDAL.GetAll();
     if (list.Exists(
         delegate(FaqEntity oldEntity)
         {
             bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
             if(checkPK)
                 result=result && oldEntity.PK_iFaqID != entity.PK_iFaqID;
             return result;
         }
     ))
     {
         list.Clear();
         throw new Exception(EX_FIELD_EXISTED);
     }
     */
 }