public ActionResult History(string keyid) { var ki = new KEYID(keyid); Wiki w = WikiService.GetWiki(ki); return View(w); }
// // GET: /Wiki/Details/5 public ActionResult Details(string keyid, string ver) { var ki = new KEYID(keyid); WikiContent wc = WikiService.GetWikiContent(ki, ver); return View(wc); }
// // GET: /Wiki/Edit/5 public ActionResult Edit(string keyid, string wikiContent) { var ki = new KEYID(keyid); var res = WikiService.AddWikiContent(MembershipHelper.GetUserName(), HttpUtility.UrlDecode(wikiContent), ki, false); return Content(res.ToAjaxMessage()); }
public Result Add(string userName, KEYID keyId, string tags) { var con = ContextFactory.GetNewContext(); foreach (var tag in tags.Split(',')) { string tagTrim = tag.Trim(); if (!string.IsNullOrEmpty(tagTrim)) { Tag tagItem = new Tag() { KID = keyId.ToString(), CrUserName = userName, CreatedTime = TimeProvider.Now, Tags = tagTrim, TagID = IDProvider.GetNewId("Tag") }; con.Tags.InsertOnSubmit(tagItem); } } con.SubmitChanges(); return Result.Success(); }
public bool HasBeenTagged(string username, KEYID kEYID) { var con = ContextFactory.GetNewContext(); var list = from t in con.Tags where t.CrUserName == username && t.KID == kEYID.ToString() select t; return list.Any(); }
public string GetTags(KEYID ki, int count) { var con = ContextFactory.GetNewContext(); var list = from t in con.Tags where t.KID == ki.ToString() group t by t.Tags into t2 orderby t2.Count() select t2.Key; return string.Join(",", list.Take(count).ToArray()); }
public ActionResult EditAnswer(long id, string wikiContent) { var ki = new KEYID("QuestionAnswer", id); var res = WikiService.AddWikiContent(MembershipHelper.GetUserName(), HttpUtility.UrlDecode(wikiContent), ki, false); return Content("obsolete:" + res.ToAjaxMessage()); }
public Result AddWikiContent(string username, string content, KEYID keyId, bool isMainReversion) { // 默认将新添加的WikiContent作为最新的Wiki内容 var con = ContextFactory.GetNewContext(); var wiki = (from w in con.Wikis where w.KID == keyId.ToString() select w).Single(); string reversion = addVersion(wiki.MaxReversion, isMainReversion); var wikiContent = CreateWikiContent(username, content, keyId, reversion); wiki.CurrentWikiContentID = wikiContent.WikiContentID; wiki.MaxReversion = wikiContent.Reversion; con.WikiContents.InsertOnSubmit(wikiContent); con.SubmitChanges(); return Result.Success(); }
WikiContent CreateWikiContent(string username, string content, KEYID keyId, string reversion) { var wikiContent = new WikiContent() { WikiContentID = IDProvider.GetNewId("WikiContent"), KID = keyId.ToString(), Content = content, CrUserName = username, CreatedTime = TimeProvider.Now, Reversion = reversion }; return wikiContent; }
public Result InsertWiki(string username, string content, KEYID keyId) { var wikiContent = CreateWikiContent(username, content, keyId, "0"); var wiki = new Wiki() { KID = keyId.ToString(), CrUserName = username, CreatedTime = TimeProvider.Now, CurrentWikiContentID = wikiContent.WikiContentID, MaxReversion = wikiContent.Reversion }; var con = ContextFactory.GetNewContext(); con.Wikis.InsertOnSubmit(wiki); con.WikiContents.InsertOnSubmit(wikiContent); con.SubmitChanges(); return Result.Success(); }
public WikiContent GetWikiContent(KEYID ki, string reversion) { var con = ContextFactory.GetNewContext(); var wc = (from w in con.WikiContents where w.KID == ki.ToString() && w.Reversion == reversion select w).Single(); return wc; }
public Wiki GetWiki(KEYID keyId) { var con = ContextFactory.GetNewContext(); var wiki = (from w in con.Wikis where w.KID == keyId.ToString() select w).Single(); return wiki; }
Result InsertRate(string userName, KEYID keyId, int score) { var con = ContextFactory.GetNewContext(); Rate rate = CreateNewRate(userName, keyId, score); con.Rates.InsertOnSubmit(rate); con.SubmitChanges(); return Result.Success(); }
Rate CreateNewRate(string userName, KEYID keyId, int score) { var rate = new Rate() { RateID = IDProvider.GetNewId("Rate"), CrUserName = userName, CreatedTime = TimeProvider.Now, KID = keyId, Score = score }; return rate; }
public Result Rate(string userName, KEYID keyId, int score) { if (CanMultipleRate) { return InsertRate(userName, keyId, score); } else { var con = ContextFactory.GetNewContext(); var rate = con.Rates.SingleOrDefault(r => r.CrUserName == userName && r.KID == keyId.ToString()); if (rate == null) { return InsertRate(userName, keyId, score); } else { return Result.Error("already have rated the object"); } } }
public Score GetScore(KEYID keyId) { // TODO:用触发器或统计表实现 var con = ContextFactory.GetNewContext(); var rates = from rate in con.Rates where rate.KID == keyId.ToString() select rate; int times = rates.Count(); int sum = times == 0 ? 0 : rates.Sum(r => r.Score); return new Score() { Sum = sum, Times = times }; }