public ActionResult LoadRating(int placeId) { var result = new AjaxOperationResult <RateInfoViewModel>(); var rateService = this.Service <IRatingService>(); var userId = User.Identity.GetUserId(); var rate = rateService.FirstOrDefault(p => p.PlaceId == placeId && p.UserId == userId); RateInfoViewModel model = new RateInfoViewModel(); if (rate != null) { model.AverageRate = rate.Point; } else { model.AverageRate = 0; } result.Succeed = true; result.AdditionalData = model; return(Json(result)); }
public ActionResult GetRateInfo(int id) { var result = new AjaxOperationResult <RateInfoViewModel>(); var rateService = this.Service <IRatingService>(); var rate = rateService.GetActive(p => p.PlaceId == id).ToList(); RateInfoViewModel model = new RateInfoViewModel(); int numOfRate = 0; double averagePoint = 0; if (rate != null && rate.Count > 0) { foreach (var item in rate) { averagePoint += item.Point; } numOfRate = rate.Count; averagePoint = averagePoint / numOfRate; } model.AverageRate = Math.Round(averagePoint, 1); model.NumberOfRate = numOfRate; result.Succeed = true; result.AdditionalData = model; return(Json(result)); }