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 Add_ShouldAddData() { var rate = new Rate() { Id = "5", Rating = RateType.Like, AuthorId = "1", VideoId = "2", }; await rateService.AddAsync(rate); var expected = rate; var actual = data.Last(); Assert.IsNotNull(actual); Assert.AreSame(expected, actual); }
public async Task <ApiResponse> addRateOfProduct(RateDto dto) { try { if (dto.Rating != 0) { var rating = _mapper.Map <Rate>(dto); await _rateService.AddAsync(rating); return(new ApiResponse("Success", rating, 200)); } return(new ApiResponse("Error")); }catch (Exception ex) { return(new ApiResponse($"Error : {ex}", ex, 400)); } }