public async Task Create(PostReactInsertViewModel viewModel)
        {
            if (!await IsInDb(viewModel))
            {
                _postReact.Add(_mappingEngine.Map <DomainClasses.Entities.PostReact>(viewModel));
                await _unitOfWork.SaveChangesAsync();
            }

            else
            {
                var webView = await _postReact.FirstAsync(a => a.UserId == viewModel.UserId && a.PostId == viewModel.PostId);

                if (webView.Like != viewModel.Like)
                {
                    _postReact.Remove(webView);
                    _postReact.Add(_mappingEngine.Map <DomainClasses.Entities.PostReact>(viewModel));
                }

                else
                {
                    _postReact.Remove(webView);
                }

                await _unitOfWork.SaveChangesAsync();
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Index(PostReactInsertViewModel viewModel)
        {
            if (viewModel.UserId == 0)
            {
                return(Json("Login"));
            }

            await _postReactService.Create(viewModel);

            ViewBag.PostId = viewModel.PostId;
            return(View(await _postReactService.GetPostReacts(viewModel.PostId)));
        }
 public async Task <bool> IsInDb(PostReactInsertViewModel viewModel)
 {
     return(await _postReact.AnyAsync(a => a.UserId == viewModel.UserId && a.PostId == viewModel.PostId));
 }