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 })); }