Beispiel #1
0
    public async Task <Vote> AddVoteAsync([FromBody] AddVoteRequest req)
    {
        if (!ModelState.IsValid || !UserToken.HasValue)
        {
            return(null);
        }

        var vote = await _votingService.GetVoteAsync(req.SpotifyTrackId, UserToken.Value);

        if (vote == null)
        {
            if (req.Liked == null)
            {
                return(null);
            }

            return(await _votingService.AddVoteAsync(req.SpotifyTrackId, UserToken.Value, req.Liked.Value, req.Comment, DateTime.UtcNow));
        }
        else
        {
            if (req.Liked == null)
            {
                await _votingService.RemoveVoteAsync(vote.Id);
            }
            else
            {
                await _votingService.UpdateVoteAsync(vote, req.Liked.Value, req.Comment);

                return(vote);
            }
        }
        return(null);
    }
Beispiel #2
0
        public async Task <HttpResponseMessage> PostAsync(string key)
        {
            string activityId = GetHeaderValueOrDefault(Request, activityHeader, () => { return(Guid.NewGuid().ToString()); });

            ServiceEventSource.Current.ServiceRequestStart("VotesController.Post", activityId); // Update or add the item.
            await _service.AddVoteAsync(key, 1, activityId, CancellationToken.None);

            ServiceEventSource.Current.ServiceRequestStop("VotesController.Post", activityId); _service.RequestCount = 1;
            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }