public async Task <IActionResult> Create(string groupid) { User user = await _userManager.GetUserAsync(User); Group group = await _context.Groups.FindAsync(groupid); if (group == null) { return(await RedirectBack($"Error: Could not find group {groupid}")); } if (!await PressPass.HasPressPass(group, _context)) { return(await RedirectBack($"Error: Group does not have a press pass!")); } if (!await group.HasPermissionAsync(user, "news")) { return(await RedirectBack($"Error: You do not have permission!")); } NewsPost post = new NewsPost() { PostID = Guid.NewGuid().ToString(), GroupID = groupid, AuthorID = user.Id }; return(View(post)); }
public async Task <IActionResult> Create(NewsPost model) { if (!ModelState.IsValid) { return(View(model)); } User user = await _userManager.GetUserAsync(User); Group group = await _context.Groups.FindAsync(model.GroupID); if (group == null) { return(await RedirectBack($"Error: Could not find group {model.GroupID}")); } if (!await PressPass.HasPressPass(group, _context)) { return(await RedirectBack($"Error: Group does not have a press pass!")); } if (!await group.HasPermissionAsync(user, "news")) { return(await RedirectBack($"Error: You do not have permission!")); } model.Timestamp = DateTime.UtcNow; await _context.NewsPosts.AddAsync(model); await _context.SaveChangesAsync(); SocketUser duser = user.GetDiscordSocket(); if (duser == null) { duser = VoopAI.discordClient.CurrentUser; } EmbedBuilder embed = new EmbedBuilder() { Color = new Color(0, 100, 255), Title = $"**{model.Title}** by *{user.UserName}*" } .WithAuthor(duser) .WithCurrentTimestamp() .WithUrl($"https://spookvooper.com/News/View?postid={model.PostID}"); embed.AddField("News Outlet", group.Name); embed.AddField("Author", user.UserName); embed.AddField("Content", $"{model.Content.Substring(0, Math.Min(model.Content.Length, 1000))}" + "..."); VoopAI.newsChannel.SendMessageAsync(embed: embed.Build()); return(RedirectToAction("View", new { postid = model.PostID })); }
public async Task <IActionResult> AddPressPass(string groupid) { Group group = await _context.Groups.FindAsync(groupid); if (group == null) { return(await RedirectBack($"Failed to find group {groupid}")); } PressPass pass = new PressPass() { GroupID = groupid }; await _context.PressPasses.AddAsync(pass); await _context.SaveChangesAsync(); StatusMessage = $"Gave press pass to {group.Name}"; return(RedirectToAction("View", "Group", new { groupid = groupid })); }
public async Task <IActionResult> RemovePressPass(string groupid) { Group group = await _context.Groups.FindAsync(groupid); if (group == null) { return(await RedirectBack($"Failed to find group {groupid}")); } PressPass pass = await _context.PressPasses.FindAsync(groupid); if (pass == null) { return(await RedirectBack($"Failed: Group does not have a press pass!")); } _context.PressPasses.Remove(pass); await _context.SaveChangesAsync(); StatusMessage = $"Removed press pass from {group.Name}"; return(RedirectToAction("View", "Group", new { groupid = groupid })); }