public ActionResult PostArtical(PostArticalModel model) { if (Session["uid"] == null) { return(RedirectToAction("Login", "Account")); } if (Convert.ToInt32(Session["uid"]) == 0) { return(RedirectToAction("Login", "Account")); } code_topics ct = new code_topics(); ct.userId = Convert.ToInt32(Session["uid"]); ct.Language = model.Language; ct.search_tags = model.Subject; ct.topic_details = model.topic_details; ct.topic_subject = model.Subject; ct.Active = 1; ct.visible = 1; ct.Allow_Comment = 1; ct.Language = model.Language; ct.created_date = DateTime.Now; ct.code_topicscol = model.topic_details; string content = model.Content; if (!string.IsNullOrEmpty(content)) { Random rnd = new Random(); string strRnd = Convert.ToString(rnd.Next()); string FilePath = Server.MapPath("~/Views/HTML/HtmlFile/"); string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms") + strRnd + ".html"; if (!Directory.Exists(Server.MapPath("~/Views/HTML/HtmlFile/"))) { Directory.CreateDirectory(Server.MapPath("~/Views/HTML/HtmlFile/")); } System.IO.File.WriteAllText(FilePath + fileName, model.Content); ct.fileName = "HtmlFile/" + fileName; } else if (!string.IsNullOrEmpty(model.FileName)) { ct.fileName = model.FileName; } ct.Create(ct, con); return(PostArtical()); }
public ActionResult EditPost(PostArticalModel model) { code_topics ct = new code_topics(); ct.topic_id = model.topicId; ct.Language = model.Language; ct.search_tags = model.Subject; ct.topic_details = model.topic_details; ct.topic_subject = model.Subject; ct.Language = model.Language; ct.code_topicscol = model.topic_details; ct.Update(ct, con); return(View(model)); }
public ActionResult EditPost(int id) { code_topics ct = code_topics.GetByid(con, id); PostArticalModel model = new PostArticalModel(); model.topicId = ct.topic_id; model.Subject = ct.topic_subject; model.Language = ct.Language; model.topic_details = ct.topic_details; if (!String.IsNullOrEmpty(ct.fileName)) { string FilePath = Server.MapPath("~/Views/HTML/"); if (System.IO.File.Exists(FilePath + ct.fileName)) { model.Content = System.IO.File.ReadAllText(FilePath + ct.fileName); } } return(View(model)); }