Пример #1
0
        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));
        }
Пример #2
0
        public Comment Create(Profile profile, CommentSendViewModel comment, News news)
        {
            var result = Create(profile, comment.Text);

            result.News = news;

            return(result);
        }
Пример #3
0
 public IActionResult Post([FromBody] CommentSendViewModel comment)
 {
     if (ModelState.IsValid)
     {
         _commentService.Create(comment);
         return(Ok(comment));
     }
     return(BadRequest(ModelState));
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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));
        }
Пример #7
0
        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));
        }