public int add(PhanHoi obj)
 {
     this._db.ds_phanhoi.Add(obj);
     //commit
     this._db.SaveChanges();
     //return ma moi nhat
     return this._db.ds_phanhoi.Max(x => x.id);
 }
 public ActionResult Index()
 {
     ViewBag.id = 5;
     PhanHoi obj = new PhanHoi();
     if(this._nhanvien!=null)
     {
         obj.nguoigui_ten = _nhanvien.tendaydu;
         obj.nguoigui_email = _nhanvien.email;
         obj.nguoigui_sdt = "";
     }
     else if(this._khachhang != null)
     {
         obj.khachhang = this._khachhang;
     }
     ViewBag.State = TempData["state"] == null ? new List<string>() : (List<string>)TempData["state"];
     ViewBag.phanhoi = obj;
     return View();
 }
 public List<string> validate(PhanHoi obj)
 {
     List<String> re = new List<string>();
     if (obj.tieude.Equals(""))
     {
         re.Add("tieude_fail");
     }
     if (obj.noidung.Equals(""))
     {
         re.Add("noidung_fail");
     }
     if (obj.khachhang == null)
     {
         if (obj.nguoigui_ten.Equals(""))
         {
             re.Add("nguoigui_ten_fail");
         }
         if (!ValidateLibrary.is_valid_email(obj.nguoigui_email))
         {
             re.Add("nguoigui_email_fail");
         }
         if (obj.nguoigui_sdt.Equals(""))
         {
             re.Add("nguoigui_sdt_fail");
         }
     }
     else
     {
         //nothing
     }
     return re;
 }
        public ActionResult Submit()
        {
            PhanHoiController ctr = new PhanHoiController();
             PhanHoi obj = new PhanHoi();
            //get post value
                string tendaydu = TextLibrary.ToString(Request["front_contact_author"]);
                string sdt = TextLibrary.ToString(Request["front_contact_phone"]);
                string email = TextLibrary.ToString(Request["front_contact_email"]);
                string tieude = TextLibrary.ToString(Request["front_contact_tieude"]);
                string noidung = TextLibrary.ToString(Request["front_contact_text"]);
                string captcha = TextLibrary.ToString(Request["front_contact_captcha"]);
            //pass to obj
                if (this._khachhang != null)
                {
                    obj.khachhang = ctr._db.ds_khachhang.Where(x => x.id == this._khachhang.id).FirstOrDefault();
                }
                else
                {
                    obj.nguoigui_email = email;
                    obj.nguoigui_sdt = sdt;
                    obj.nguoigui_ten = tendaydu;
                }
                obj.tieude = tieude;
                obj.noidung = noidung;
             //validate
                List<string> validate = ctr.validate(obj);
                //xét captcha
                if (!this.get_captcha_string().ToLower().Equals(captcha.ToLower()))
                {
                    validate.Add("captcha_fail");
                }
            //Check ok
                if (validate.Count == 0)
                {
                    ctr.add(obj);
                    validate.Add("success");
                }

                ViewBag.State = validate;
                ViewBag.phanhoi = obj;
                return View("Index");
        }