public ActionResult AddArticle(string TITLE, string CONTENT, int[] CATEGORIES) { try { string nGuid = Guid.NewGuid().ToString("N"); IDatabase2 db = DatabaseFactory.GetDbObject(DbSettings.TransactionMode); IQueryGenerator gen = QueryGeneratorFactory.GetDbObject(); gen.TableName = "article"; gen.AddDataParameter("TITLE", TITLE); gen.AddDataParameter("TEXT", CONTENT); gen.AddDataParameter("INSERT_DATE", DateTime.Now); gen.AddDataParameter("AUTHOR", "vyigity"); gen.AddDataParameter("ID_GUID", nGuid); db.ExecuteQuery(gen.GetInsertCommand()); IQueryGenerator gen2 = QueryGeneratorFactory.GetDbObject(); gen2.SelectText = "select ID from article where "; gen2.FilterText = "ID_GUID = :p1"; gen2.AddFilterParameter("p1", nGuid); if (CATEGORIES != null && CATEGORIES.Length > 0) { int id = Util.GetProperty <int>(db.GetSingleValue(gen2.GetSelectCommandBasic())); foreach (int i in CATEGORIES) { IQueryGenerator gen3 = QueryGeneratorFactory.GetDbObject(); gen3.TableName = "article_category"; gen3.AddDataParameter("ARTICLE_ID", id); gen3.AddDataParameter("CATEGORY_ID", i); db.ExecuteQuery(gen3.GetInsertCommand()); } } db.Commit(); ProcessView(); return(RedirectToAction("ManageArticle")); } catch { return(RedirectToAction("Index")); } }
public ActionResult AddCategory(Category param) { IDatabase2 db = DatabaseFactory.GetDbObject(); IQueryGenerator gen = QueryGeneratorFactory.GetDbObject(); gen.TableName = "category"; gen.AddDataParameter("LABEL_TEXT", param.LABEL_TEXT); db.ExecuteQuery(gen.GetInsertCommand()); List <Category> cList = ProcessView(); return(View("Index", cList)); }
public ActionResult AddComment(Comment param) { IDatabase2 db = DatabaseFactory.GetDbObject(); IQueryGenerator gen = QueryGeneratorFactory.GetDbObject(); gen.TableName = "comment"; gen.AddDataParameter("ID", Guid.NewGuid().ToString("N")); gen.AddDataParameter("ARTICLE_ID", param.ARTICLE_ID); gen.AddDataParameter("COMMENT_TEXT", param.COMMENT_TEXT); gen.AddDataParameter("USER_NAME", param.USER_NAME); gen.AddDataParameter("INSERT_DATE", DateTime.Now); db.ExecuteQuery(gen.GetInsertCommand()); return(Json(new { })); }
public ActionResult UpdateArticle(int ARTICLE_ID, string TITLE, string CONTENT, int[] CATEGORIES) { try { IDatabase2 db = DatabaseFactory.GetDbObject(DbSettings.TransactionMode); IQueryGenerator gen = QueryGeneratorFactory.GetDbObject(); gen.TableName = "article"; gen.AddDataParameter("TITLE", TITLE); gen.AddDataParameter("TEXT", CONTENT); gen.AddDataParameter("UPDATE_DATE", DateTime.Now); gen.AddDataParameter("AUTHOR", "vyigity"); gen.FilterText = " where ID=:p1"; gen.AddFilterParameter("p1", ARTICLE_ID); db.ExecuteQuery(gen.GetUpdateCommand()); db.ExecuteQuery("delete from article_category where article_id = " + ARTICLE_ID); if (CATEGORIES != null && CATEGORIES.Length > 0) { foreach (int i in CATEGORIES) { IQueryGenerator gen3 = QueryGeneratorFactory.GetDbObject(); gen3.TableName = "article_category"; gen3.AddDataParameter("ARTICLE_ID", ARTICLE_ID); gen3.AddDataParameter("CATEGORY_ID", i); db.ExecuteQuery(gen3.GetInsertCommand()); } } db.Commit(); return(RedirectToAction("ManageArticle")); } catch { return(RedirectToAction("ArticleUpdate")); } }