public static ModelResult <T> CheckToken <T>(string token, BSDNContext context) { ModelResult <T> result; if (token == null) { result = new ModelResult <T>(405, default, "Need Token");
public static async Task CreateCommentNotice(Comment comment, BSDNContext context, int userId, string type) { if (userId == 0) { return; } Notice notice = new Notice(userId, $@"New {type}", $@"/api/article/{comment.ArticleId}"); await context.Notices.AddAsync(notice); await context.SaveChangesAsync(); }
public static async Task CreateFollowNotice(UserFollow userFollow, BSDNContext context) { User follower = await context.Users.FirstOrDefaultAsync(u => u.UserId == userFollow.FollowerId); User following = await context.Users.FirstOrDefaultAsync(u => u.UserId == userFollow.FollowingId); Notice notice = new Notice(following.UserId, $@"New Follower|{follower.Nickname}|{follower.UserId}", null); await context.AddAsync(notice); await context.SaveChangesAsync(); }
public static string GenerateSessionToken(User user, BSDNContext context) { var rawToken = user.Nickname + user.UserId + user.Email + DateTime.Now.ToString(); var md5 = MD5.Create(); var data = md5.ComputeHash(Encoding.UTF8.GetBytes(rawToken)); var stringBuilder = new StringBuilder(); foreach (var ch in data) { stringBuilder.Append(ch.ToString("x2")); } string token = stringBuilder.ToString(); Session session = context.Sessions.FirstOrDefault(s => s.SessionToken == token); return(session == null ? token : null); }
public static async Task CreateArticleNotice(Article article, BSDNContext context) { User userResult = await context.Users.FirstOrDefaultAsync(u => u.UserId == article.UserId); List <Notice> notices = await context.UserFollows .Where(uf => uf.FollowingId == userResult.UserId) .Select(uf => uf.FollowerId) .Select(uid => new Notice(uid, $@"New Article|{article.Title}|{article.ArticleId}", $@"/api/article/{article.ArticleId}")) .ToListAsync(); foreach (var notice in notices) { await context.Notices.AddAsync(notice); } await context.SaveChangesAsync(); }
public ArticleTagController(BSDNContext context) { _context = context; }
public FollowController(BSDNContext context) { _context = context; }
public SessionController(BSDNContext context) { _context = context; }
public CommentController(BSDNContext context) { _context = context; }
public TagController(BSDNContext context) { _context = context; }
public UserController(BSDNContext context) { _context = context; }
public NoticeController(BSDNContext context) { _context = context; }
public FileController(BSDNContext context) { _context = context; }