public bool RateProduct(Rating rating)
 {
     if (_ratingRepository.HasRated(rating.FarmerId, rating.ProductId))
         return false;
     if (_productRepository.GetProductByProductId(rating.ProductId).FarmerId.Equals(rating.FarmerId))
         return false;
     _ratingRepository.AddRating(rating);
     return true;
 }
 public IHttpActionResult RateProduct(RatingViewModel ratingViewModel)
 {
     var rating = new Rating
                      {
                          FarmerId = ratingViewModel.FarmerId,
                          ProductId = ratingViewModel.ProductId,
                          Value = ratingViewModel.Value
                      };
     if(_ratingService.RateProduct(rating))
     {
         return Ok(ratingViewModel);
     }
     return BadRequest("Can't Rate");
 }
 public void Init()
 {
     _ratingService = new RatingService();
     _rating = new Rating()
     {
         FarmerId = 1,
         ProductId = 1,
         Value = 4
     };
     _rating2 = new Rating()
     {
         FarmerId = 1,
         ProductId = 1,
         Value = 3
     };
 }
 public bool DeleteRating(Rating rating)
 {
     _appContext.Ratings.Remove(rating);
     return _appContext.SaveChanges() > 0;
 }
 public bool UpdateRating(Rating rating)
 {
     _appContext.Entry(rating).State=EntityState.Modified;
     return _appContext.SaveChanges() > 0;
 }
 public int AddRating(Rating rating)
 {
     _appContext.Ratings.Add(rating);
     _appContext.SaveChanges();
     return rating.RatingId;
 }