/// <summary>
        /// Check the rating and calculate average rating
        /// </summary>
        /// <param name="viewratingDTO"></param>
        /// <returns>
        /// average rating value
        /// </returns>
        public double GetAverageRating([FromBody] ViewRatingDTO viewratingDTO)
        {
            var entities         = new FoodfeedbackDBContext();
            var viewratingresult = entities.Feedback.Where(r => r.SelectDate == viewratingDTO.SelectDate && r.TypeOfMeal == viewratingDTO.TypeOfMeal)
                                   .GroupBy(g => g.TypeOfMeal, r => r.Rating)
                                   .Select(g => new ResponseDTO()
            {
                Average_Rating = g.Average()
            }).FirstOrDefault();

            if (viewratingresult == null)
            {
                return(0);
            }
            else
            {
                var average = Convert.ToDouble(viewratingresult.Average_Rating);
                return(average);
            }
        }
Пример #2
0
 /// <summary>
 /// call the service and check if the user exists
 /// </summary>
 public IActionResult GetAverage([FromBody] ViewRatingDTO viewratingDTO)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var result = _viewRatingService.GetAverageRating(viewratingDTO);
             if (result != 0)
             {
                 return(Ok(result));
             }
             else
             {
                 return(BadRequest(result));
             }
         }
         catch (Exception)
         {
             return(StatusCode(500));
         }
     }
     return(BadRequest());
 }