Beispiel #1
0
 public void addRankExp(IEnumerable <HistoryRanking> blogs, List <int> reward, string type)
 {
     for (int i = 0; i < blogs.Count() && i < reward.Count; i++)
     {
         var rank = blogs.ElementAt(i);
         addExp(rank.Author, reward[i]);
         var content = string.Format("恭喜!您的投稿 <a href='/gm{3}'>{4}</a> 今天在{0}上位居第{1},特此奖励{2}点绅士度和棒棒糖!", type.Substring(0, 2), i + 1, reward[i], rank.BlogID, rank.BlogTitle);
         _msgUtil.SendRankNotice(rank.Author, content);
         _adminUtil.log("admin", type + "#" + (i + 1) + "(" + reward[i] + ")", rank.Author + "@gm" + rank.BlogID);
     }
 }
Beispiel #2
0
        public async Task DeleteBlogAsync(int id, string reason = null)
        {
            Blog b = await _db.Blogs.FindAsync(id);

            if (b == null)
            {
                return;
            }
            _db.TagsInBlogs.RemoveRange(_db.TagsInBlogs.Where(tib => tib.BlogID == b.BlogID));
            var posts = await _db.Posts.Where(p => p.IdType == ItemType.Blog && p.ItemId == b.BlogID).ToListAsync();

            if (posts.Count != 0)
            {
                _db.Posts.RemoveRange(posts);
            }
            var auditTypes = await _db.BlogAudits.Where(ba => ba.BlogID == id).Select(ba => ba.AuditAction).Distinct().ToListAsync();

            if (auditTypes.Any(ba => ba == BlogAudit.Action.Approve || ba == BlogAudit.Action.Deny) && auditTypes.Any(ba => ba == BlogAudit.Action.VoteApprove || ba == BlogAudit.Action.VoteDeny))
            {
                // If vote accuracy was affected by this blog, move all audits to BlogID = 0 to preserve them.
                await _db.Database.ExecuteSqlCommandAsync(@"WITH maxv AS (SELECT max(BlogVersion) AS v FROM BlogAudits WHERE BlogID = 0)
                        UPDATE BlogAudits SET BlogVersion = BlogVersion + ISNULL(maxv.v, 0), BlogID = 0 FROM BlogAudits, maxv WHERE BlogID = @id", new SqlParameter("@id", id));
            }
            try
            {
                if (b.IsLocalImg)
                {
                    IEnumerable <string> name = b.ImagePath.Split(';');
                    await _uploadUtil.DeleteFilesAsync(name.Concat(new[] { name.First().Replace("/upload/", "/thumbs/") }));
                }
            }
            finally
            {
                _db.Blogs.Remove(b);
                await _db.SaveChangesAsync();
            }
            _adminUtil.log(HttpContext.User.Identity.Name, "deleteblog", b.BlogID + ": " + b.BlogTitle, reason);
        }