Esempio n. 1
0
 public IList <RatingViewModel> GetCommentRatingsById(Guid objectId, RatingObjectType objectType)
 {
     _unitOfWork.BeginTransaction();
     if (objectType.Equals(RatingObjectType.ORDER))
     {
         var order = _orderRepository.GetById(objectId);
         if (order == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
         }
         var ratings          = _ratingRepository.GetCommentRatingsById(order);
         var ratingsViewModel = ratings.Select(x => x.MapToViewModel()).ToList();
         return(ratingsViewModel);
     }
     else
     {
         var product = _productRepository.GetById(objectId);
         if (product == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.ProductException.NOT_FOUND);
         }
         var ratings          = _ratingRepository.GetCommentRatingsById(product);
         var ratingsViewModel = ratings.Select(x => x.MapToViewModel()).ToList();
         return(ratingsViewModel);
     }
 }
Esempio n. 2
0
 public double GetAverageRatingValue(Guid objectId, RatingObjectType objectType)
 {
     _unitOfWork.BeginTransaction();
     if (objectType.Equals(RatingObjectType.ORDER))
     {
         var order = _orderRepository.GetById(objectId);
         if (order == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
         }
         var average = _ratingRepository.GetAverageRatingValue(order);
         _unitOfWork.Commit();
         return(average);
     }
     else
     {
         var product = _productRepository.GetById(objectId);
         if (product == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.ProductException.NOT_FOUND);
         }
         var average = _ratingRepository.GetAverageRatingValue(product);
         _unitOfWork.Commit();
         return(average);
     }
 }
Esempio n. 3
0
 public Rating(User user, Guid objectId, RatingObjectType objectType, int value, string comment, bool showName)
 {
     _user       = user;
     _objectId   = objectId;
     _objectType = objectType;
     _value      = value;
     _comment    = comment;
     _showName   = showName;
 }
Esempio n. 4
0
 public RatingValuesViewModel GetRatingValues(Guid ObjectId, RatingObjectType ObjectType)
 {
     _unitOfWork.BeginTransaction();
     if (ObjectType.Equals(RatingObjectType.ORDER))
     {
         var order = _orderRepository.GetById(ObjectId);
         if (order == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
         }
         var values  = new RatingValuesViewModel();
         var ratings = _ratingRepository.GetRatingsById(order);
         values.One   = ratings.AsQueryable <Rating>().Where(x => x.Value == 1).ToList().Count;
         values.Two   = ratings.AsQueryable <Rating>().Where(x => x.Value == 2).ToList().Count;
         values.Three = ratings.AsQueryable <Rating>().Where(x => x.Value == 3).ToList().Count;
         values.Four  = ratings.AsQueryable <Rating>().Where(x => x.Value == 4).ToList().Count;
         values.Five  = ratings.AsQueryable <Rating>().Where(x => x.Value == 5).ToList().Count;
         values.Total = values.One + values.Two + values.Three + values.Four + values.Five;
         _unitOfWork.Commit();
         return(values);
     }
     else
     {
         var product = _productRepository.GetById(ObjectId);
         if (product == null)
         {
             _unitOfWork.Commit();
             throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
         }
         var values  = new RatingValuesViewModel();
         var ratings = _ratingRepository.GetRatingsById(product);
         values.One   = ratings.AsQueryable <Rating>().Where(x => x.Value == 1).ToList().Count;
         values.Two   = ratings.AsQueryable <Rating>().Where(x => x.Value == 2).ToList().Count;
         values.Three = ratings.AsQueryable <Rating>().Where(x => x.Value == 3).ToList().Count;
         values.Four  = ratings.AsQueryable <Rating>().Where(x => x.Value == 4).ToList().Count;
         values.Five  = ratings.AsQueryable <Rating>().Where(x => x.Value == 5).ToList().Count;
         values.Total = values.One + values.Two + values.Three + values.Four + values.Five;
         _unitOfWork.Commit();
         return(values);
     }
 }
Esempio n. 5
0
        public ActionResult GetRatingValues(Guid id, RatingObjectType type) //0 order 1 product
        {
            var values = _ratingService.GetRatingValues(id, type);

            return(Json(values));
        }
Esempio n. 6
0
        public ActionResult GetCommentRatingsById(Guid id, RatingObjectType type) //0 order 1 product
        {
            var ratings = _ratingService.GetCommentRatingsById(id, type);

            return(Json(ratings));
        }
Esempio n. 7
0
        public ActionResult GetAverageRatingValue(Guid id, RatingObjectType type) //0 order 1 product
        {
            var average = _ratingService.GetAverageRatingValue(id, type);

            return(Json(average));
        }