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); } }
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); } }
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); } }