Esempio n. 1
0
 public void AddComment(Model model,string sanPhamId)
 {
     if (model != null&&sanPhamId!=null)
     {
         List<Model> list;
         if (table.TryGetValue(sanPhamId, out list))
         {
             list.Add(model);
             table[sanPhamId] = list;
         }
         else
         {
             list=new List<Model>();
             list.Add(model);
             table.Add(sanPhamId, list);
         }
     }
 }
Esempio n. 2
0
        public ActionResult LoadDetailPage(int bookId)
        {
            Book b=db.Books.FirstOrDefault(book => book.BookId == bookId);
            b.NumberOfViews += 1;
            db.Entry(b).State = System.Data.EntityState.Modified;
            StringBuilder str = new StringBuilder();
            string fileName = bookId.ToString() + ".txt";//Lay ten san pham la ten file
            string path = Server.MapPath("~/Json File/ListComment");
            List<Model> list12 = json.JsonFileToObject(bookId.ToString(), path, 10);

            Model model = new Model();
            list12.Reverse();//Dao nguoc list de y kien moi nhat duoc doc dau tien
            model.ListComment = list12;

            ViewBag.sss = model;
            ViewBag.NgaMap = b;
            ViewBag.aaa = str;

            return View(b);
        }
Esempio n. 3
0
        public ActionResult LoadDetailPage(string bookID, Model model)
        {
            try
            {
                string fileName = bookID + ".txt";//Lay ten san pham la ten file
                string path = Server.MapPath("~/Json File/ListComment");//Lay duong dan chua file .txt
                List<Model> list12 = json.JsonFileToObject(bookID, path, 10);
                int intBookID=int.Parse(bookID);
                Book sp = db.Books.FirstOrDefault(p => p.BookId == intBookID);
                StringBuilder str = new StringBuilder();
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                ViewBag.NgaMap = sp;

                ViewBag.aaa = str;

                if (ModelState.IsValid)
                {
                    json.ObjectToJsonFile(bookID, new List<Model>() { model }, path);
                    list12.Add(model);
                    list12.Reverse();
                    model.ListComment = list12;
                    if (Request.IsAjaxRequest())
                    {
                        return PartialView("~/Views/Partial/_PartialViewComment.cshtml", model);
                    }
                    return View(model);
                }
                list12.Reverse();
                model.ListComment = list12;
                TempData["ErrorMessage"] = "Error: Captcha is not valid";
                if (Request.IsAjaxRequest())
                    return PartialView("~/Views/Partial/_PartialViewComment.cshtml", model);
                ViewBag.sss = model;
                return View(sp);
            }
            catch(Exception ex)
            {
                ViewBag.Error = ex.Message;
                return View("Error");
            }
        }