Exemplo n.º 1
0
        public ActionResult SuaFAQ(FAQ faq)
        {
            String path = "E:/029_HCM_HUTECH_01_NET_CF/SetPortal/SetPortal/FileTaiLieuFAQ" + faq.FileName;
            // String content = faq.Question;
            String content = "Câu hỏi: " + faq.Question + Environment.NewLine + "Câu trả lời: " + faq.Answer;
            System.IO.File.WriteAllText(path, content);

            FAQ faq2 = db.FAQs.Single(n => n.FaqID == faq.FaqID);
            faq2.MaChuDeFAQ = faq.MaChuDeFAQ;
            faq2.Question = faq.Question;
            faq2.Answer = faq.Answer;
            db.SaveChanges();
            return RedirectToAction("QuanLyFAQ");
        }
Exemplo n.º 2
0
        public ActionResult AddFAQ(FAQ faq)
        {
            ViewBag.MaChuDeFAQ = new SelectList(db.ChuDeFAQs.ToList(), "MaChuDeFAQ", "TenChuDeFAQ");

            int dem;
            dem = db.FAQs.Count();
            string dem2 = (dem + 1).ToString();
            FAQ kiemtra = db.FAQs.SingleOrDefault(n => n.FileName == dem2 + ".doc");
            if (kiemtra != null)
            {
                dem2 = dem2 + "(1)";
            }
            String path = "E:/029_HCM_HUTECH_01_NET_CF/SetPortal/SetPortal/FileTaiLieuFAQ/" + dem2 + ".doc";
            String content = "Câu hỏi: " + faq.Question + Environment.NewLine + "Câu trả lời: " + faq.Answer;
            System.IO.File.WriteAllText(path, content);

            //Luu tat ca vao database
            faq.FileName = dem2 + ".doc";

            db.FAQs.Add(faq);
            db.SaveChanges();
            Response.Write("<script>alert('Add new thành công!');</script>");

            return View();
        }