Beispiel #1
0
        public ActionResult Update(練習B_Table model)
        {
            var f = Request.Files["Up練習BImg"];

            if (f.ContentLength > 0)
            {
                var path練習BImg = Server.MapPath("~/img/練習BImg/" + model.練習BImg);
                if (System.IO.File.Exists(path練習BImg))
                {
                    System.IO.File.Delete(path練習BImg);
                    model.練習BImg = f.FileName;
                    path練習BImg   = Server.MapPath("~/img/練習BImg/" + model.練習BImg);
                    f.SaveAs(path練習BImg);
                }
                else
                {
                    model.練習BImg = f.FileName;
                    path練習BImg   = Server.MapPath("~/img/練習BImg/" + model.練習BImg);
                    f.SaveAs(path練習BImg);
                }
            }

            try
            {
                var b = model.練習B;
                b         = b.Replace("<", "<ruby>");
                b         = b.Replace(">", "</ruby>");
                b         = b.Replace("{", "<rt>");
                b         = b.Replace("}", "</rt>");
                model.練習B = b;

                var a = model.練習BAnswer;
                a = a.Replace("<", "<ruby>");
                a = a.Replace(">", "</ruby>");
                a = a.Replace("{", "<rt>");
                a = a.Replace("}", "</rt>");
                model.練習BAnswer = a;

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ModelState.Clear();
                ModelState.AddModelError("", "Update thành công!");
            }
            catch
            {
                ModelState.AddModelError("", "Update thất bại!");
            }
            ViewBag.第課List = new SelectList(db.第課_Table, "第課ID", "第課Name");
            return(View("Index"));
        }
Beispiel #2
0
        public ActionResult Insert(練習B_Table model)
        {
            var f = Request.Files["Up練習BImg"];

            if (f.ContentLength > 0)
            {
                model.練習BImg = f.FileName;
                var path練習BImg = Server.MapPath("~/img/練習BImg/" + model.練習BImg);
                f.SaveAs(path練習BImg);
            }
            else
            {
                model.練習BImg = "No Img File";
            }

            try
            {
                var b = model.練習B;
                b         = b.Replace("<", "<ruby>");
                b         = b.Replace(">", "</ruby>");
                b         = b.Replace("{", "<rt>");
                b         = b.Replace("}", "</rt>");
                model.練習B = b;

                var a = model.練習BAnswer;
                a = a.Replace("<", "<ruby>");
                a = a.Replace(">", "</ruby>");
                a = a.Replace("{", "<rt>");
                a = a.Replace("}", "</rt>");
                model.練習BAnswer = a;

                db.練習B_Table.Add(model);
                db.SaveChanges();
                ModelState.Clear();
                ModelState.AddModelError("", "Thêm thành công!");
            }
            catch
            {
                ModelState.AddModelError("", "Thêm thất bại!");
            }
            ViewBag.第課List = new SelectList(db.第課_Table, "第課ID", "第課Name");
            return(View("Index"));
        }