Beispiel #1
0
 public async Task <IActionResult> Get([FromQuery] string userId)
 {
     try
     {
         ApplicationUser user = null;
         if (userId != null)
         {
             user = await _userManager.FindByIdAsync(userId);
         }
         //var first = _voteService.GetAllGifts().Result;
         ////var two = first.VoteUsers;
         //return Ok(first);
         var list = new List <VoteViewModel.Vote>();
         foreach (var item in await _voteService.GetAllGifts())
         {
             var data = _mapper.Map <Vote, VoteViewModel.Vote>(item);
             data.VotesAgree    = item.VoteUsers.Count(x => x.Value);
             data.VotesDisagree = item.VoteUsers.Count(x => !x.Value);
             list.Add(data);
             if (user != null)
             {
                 data.UserVote = item.VoteUsers.FirstOrDefault(x => x.UserId == user.Id)?.Value;
             }
         }
         //var map = _mapper.Map<IEnumerable<VoteViewModel.Vote>>(await _voteService.GetAllGifts());
         return(Ok(list));
     }
     catch (Exception e)
     {
         return(BadRequest(_messageModelBuilder.CreateModel("500", e.Message)));
     }
 }