public async Task <CommentViewModel> Send(CommentSendViewModel model) { var user = await userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{userManager.GetUserId(User)}'."); } var profile = await dbContext.Profiles.FindAsync(user.Id); var comment = model.ContentType == "Anime" ? await CreateAnimangaComment(db => db.Anime, profile, model) : model.ContentType == "Manga" ? await CreateAnimangaComment(db => db.Manga, profile, model) : model.ContentType == "News" ? await CreateNewsComment(profile, model) : null; if (comment == null) { throw new ArgumentException($"Invalid argument '{model.ContentType}'"); } profile.Comments.Add(comment); await dbContext.SaveChangesAsync(); return(new CommentViewModel().Initialize(comment, timestampFormatter)); }
public Comment Create(Profile profile, CommentSendViewModel comment, News news) { var result = Create(profile, comment.Text); result.News = news; return(result); }
public IActionResult Post([FromBody] CommentSendViewModel comment) { if (ModelState.IsValid) { _commentService.Create(comment); return(Ok(comment)); } return(BadRequest(ModelState)); }
public Comment Create(Profile profile, CommentSendViewModel comment, Animanga animanga) { var result = Create(profile, comment.Text); result.Anime = animanga as Anime; result.Manga = animanga as Manga; return(result); }
public void Create(CommentSendViewModel commentSendViewModel) { Comment comment = new Comment(); comment.Author = commentSendViewModel.Author; comment.CommentText = commentSendViewModel.CommentText; comment.PostId = commentSendViewModel.PostId; comment.DateTime = DateTime.Now; _commentRepository.Create(comment); }
private async Task <Comment> CreateNewsComment(Profile profile, CommentSendViewModel commentInfo) { var news = await dbContext.News.FindAsync(int.Parse(commentInfo.ContentKey)); return(commentCreater.Create(profile, commentInfo, news)); }
private async Task <Comment> CreateAnimangaComment <T>(Func <IDbContext, IQueryable <T> > func, Profile profile, CommentSendViewModel commentInfo) where T : Animanga { var animanga = await func(dbContext).FirstOrDefaultAsync(a => a.Key == commentInfo.ContentKey); return(commentCreater.Create(profile, commentInfo, animanga)); }