public async Task <IResult> GetProductRatingById(int productId) { var result = new Result() { Operation = Operation.Read, Status = Status.Success }; try { var userDetail = _specificClaim.GetSpecificClaim("Id"); var rating = await _productRepository.GetProductRatingById(userDetail, productId); if (rating.Status != Status.Success) { return(rating); } ProductRatingReviewViewModel viewModel = new ProductRatingReviewViewModel(); ProductRatingReviewModel productRating = rating.Body; viewModel.MapFromModel(productRating); viewModel.UserName = _specificClaim.GetSpecificClaim("userName"); result.Body = viewModel; result.StatusCode = HttpStatusCode.OK; return(result); } catch (Exception e) { result.Status = Status.Error; result.StatusCode = HttpStatusCode.InternalServerError; result.Body = e; result.Message = e.Message; return(result); } }
public async Task <IResult> GetProductReviewList(int id, DataHelperModel dataHelper) { var result = new Result() { Operation = Operation.Read, Status = Status.Success }; try { var rating = _productRepository.GetReviewList(id); if (rating.Count() == 0) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "Ratings do not exist for the product."; return(result); } var list = rating; list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder); var resultCount = list.Count(); var pagedList = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize); var resultList = await pagedList.ToListAsync(); var ratingViewModel = new List <ProductRatingReviewViewModel>(); ratingViewModel = resultList.Select(r => { var ratingViewObj = new ProductRatingReviewViewModel(); ratingViewObj.MapFromModel(r); return(ratingViewObj); }).ToList(); ResultModel resultModel = new ResultModel(); resultModel.ProductRatingReviewResult = ratingViewModel; resultModel.TotalCount = resultCount; result.Status = Status.Success; result.StatusCode = HttpStatusCode.OK; result.Body = resultModel; return(result); } catch (Exception e) { result.Status = Status.Success; result.StatusCode = HttpStatusCode.InternalServerError; result.Body = e; result.Message = e.Message; return(result); } }