Esempio n. 1
0
        public async Task <IActionResult> Add([FromBody] AddRateBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetFirstError()));
            }
            var authorId = User.GetId();

            if (authorId == null)
            {
                return(Unauthorized());
            }
            var hasVoted = await rateService.CheckIfVotedAsync(model.VideoId, authorId);

            if (!hasVoted)
            {
                var rate = Mapper.Map <Rate>(model);
                rate.AuthorId = authorId;

                await rateService.AddAsync(rate);

                return(Ok());
            }
            return(BadRequest());
        }
        public async Task CheckIfVoted_ShouldReturnCorrectBoolean(string videoId, string authorId, bool expected)
        {
            var actual = await rateService.CheckIfVotedAsync(videoId, authorId);

            Assert.AreEqual(expected, actual);
        }