public async Task <IActionResult> OnGetAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } await LoadAsync(user); return(Page()); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = await _userManager.GetUserAsync(User); var clubThread = new ClubThread { Author = user, Title = ClubThread.Title, Body = ClubThread.Body, ClubId = ClubThread.ClubId, CreationDate = DateTime.Now, CommentsThread = new CommentsThread() }; await _context.ClubThreads.AddAsync(clubThread); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { id = ClubThread.ClubId })); }
public async Task <CountReturn> GetVotes(long storyId) { var user = await _userManager.GetUserAsync(User); var count = await _context.Votes .AsNoTracking() .CountAsync(v => v.StoryId == storyId); var didUserVote = await _context.Votes .AsNoTracking() .AnyAsync(v => v.User == user && v.StoryId == storyId); return(new CountReturn { Count = count, DidVote = didUserVote }); }
public async Task <ActionResult <InviteCodeApiDto> > PostInviteCode() { var currentUser = await _userManager.GetUserAsync(User); var issuedCount = await _context.InviteCodes .CountAsync(ic => ic.IssuedById == currentUser.Id); if (issuedCount >= _config.MaxInvitesPerUser) { return(Unauthorized($"You cannot generate more than {_config.MaxInvitesPerUser} codes")); } var code = new InviteCode { Code = GenerateCode(), IssuedBy = currentUser }; await _context.InviteCodes.AddAsync(code); await _context.SaveChangesAsync(); return(_mapper.Map <InviteCode, InviteCodeApiDto>(code)); }