public async Task <JsonResult> ListData(Guid id) { var userId = this.User.Identity.GetUserIdGuid(); var user = await _userService .QueryUser() .Include(u => u.ReceivedVotes) .Include(u => u.ReceivedVotes.Select(v => v.RatedByUser)) .SingleAsync(u => u.Id == id); var votes = user.ReceivedVotes .Select(v => new VoteDto { VoteId = v.Id, Comment = v.Comment, Rate = v.Rate, RatedOn = v.RatedOn, VotedByUser = new UserViewDto { Gender = v.RatedByUser.Gender, Name = v.RatedByUser.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(v.RatedByUser.ProfilePhotoUrl), UserId = v.RatedByUser.Id } }); var voteListDto = new VoteListDto { CanVote = !userId.HasValue || userId.Value != id, Votes = votes.ToList() }; return(Json(voteListDto, JsonRequestBehavior.AllowGet)); }
public async Task UpdateAsync(Guid currentVoteListId, VoteListDto newVoteList) { var voteList = await _domainContext.VoteLists.FirstOrDefaultAsync(e => e.Id == currentVoteListId); if (voteList != null) { voteList.Name = newVoteList.Name; voteList.Count = newVoteList.Count ?? 0; voteList.VoteId = newVoteList.VoteId.Value; _domainContext.VoteLists.Update(voteList); } }
public VoteList Add(VoteListDto addedVoteList) { var voteList = new VoteList() { Name = addedVoteList.Name, Count = addedVoteList.Count ?? 0, VoteId = addedVoteList.VoteId.Value, }; _domainContext.VoteLists.Add(voteList); return(voteList); }