public ActionResult Insert()
 {
     AdminGhiChuModel tnew = new AdminGhiChuModel();
     dbFirstStepDataContext db = new dbFirstStepDataContext();
     ViewBag.DanhMuc = db.EntityUsers.ToList();
     return View();
 }
 public ActionResult Edit(AdminGhiChuModel DM, HttpPostedFileBase Image)
 {
     try
     {
         if (Image != null)
         {
             ImageHelper imgHelper = new ImageHelper();
             string encodestring = imgHelper.encodeImageFile(Image);
             if (encodestring == "!")
                 return RedirectToAction("Index", "Error", new { errorMsg = "Can't upload Images" });
             var path = Path.Combine(Server.MapPath("~/Content/Images/GhiChu"), encodestring);
             Image.SaveAs(path);
             DM.HinhAnh = encodestring;
             DM.IdUser = null;
         }
         else
         {
             DM.IdUser = DM.IdUser > 0 ? DM.IdUser : null;
         }
         AdminGhiChuModel.Edit(DM);
         return RedirectToAction("Index", "AdminGhiChu");
     }
     catch
     {
         return RedirectToAction("Index", "Error");
     }
 }
 public ActionResult Edit(int Id)
 {
     AdminGhiChuModel tnew = new AdminGhiChuModel();
     dbFirstStepDataContext db = new dbFirstStepDataContext();
     ViewBag.DanhMuc = db.EntityUsers.ToList();
     return View(AdminGhiChuModel.LayModel(Id));
 }
 public static void Edit(AdminGhiChuModel Banner)
 {
     dbFirstStepDataContext db = new dbFirstStepDataContext();
     EntityQuote Faq = db.EntityQuotes.Where(p => p.Id == Banner.Id).First();
     Faq.IdUser = Banner.IdUser;
     Faq.Image = Banner.HinhAnh;
     Faq.NoiDung = Banner.NoiDung;
     db.SubmitChanges();
 }
 public static AdminGhiChuModel LayModel(int Id)
 {
     AdminGhiChuModel Ban = new AdminGhiChuModel();
     dbFirstStepDataContext db = new dbFirstStepDataContext();
     EntityQuote tnew = db.EntityQuotes.Where(p => p.Id == Id).First();
     Ban.Id = tnew.Id;
     Ban.IdUser = tnew.IdUser;
     Ban.HinhAnh = tnew.Image;
     Ban.NoiDung = tnew.NoiDung;
     return Ban;
 }
        public ActionResult Insert(AdminGhiChuModel DM, HttpPostedFileBase Image)
        {
            try
            {
                dbFirstStepDataContext db = new dbFirstStepDataContext();
                EntityQuote ban = new EntityQuote();
                if (Image != null)
                {
                    ImageHelper imgHelper = new ImageHelper();
                    string encodestring = imgHelper.encodeImageFile(Image);
                    db.SubmitChanges();
                    if (encodestring == "!")
                        return RedirectToAction("Index", "Error", new { errorMsg = "Can't upload Images" });
                    var path = Path.Combine(Server.MapPath("~/Content/Images/GhiChu"), encodestring);
                    Image.SaveAs(path);
                    ban.Image = encodestring;
                    ban.IdUser = null;
                }
                else
                {
                    ban.IdUser = DM.IdUser>0?DM.IdUser:null;
                }
                ban.NoiDung = DM.NoiDung;
                db.EntityQuotes.InsertOnSubmit(ban);
                db.SubmitChanges();

                return RedirectToAction("Index", "AdminGhiChu");
            }
            catch
            {
                return RedirectToAction("Index", "Error");
            }
        }