Exemplo n.º 1
0
        public ActionResult History(string keyid)
        {
            var ki = new KEYID(keyid);
            Wiki w = WikiService.GetWiki(ki);

            return View(w);
        }
Exemplo n.º 2
0
        //
        // 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);
        }
Exemplo n.º 3
0
        //
        // 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());
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
 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());
 }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
 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();
 }
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
        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");
                }
            }
        }
Exemplo n.º 16
0
 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
     };
 }