Ejemplo n.º 1
0
 public void AddDishReview(string owner, int dish_id, int mark, string text)
 {
     dishreview dr = new dishreview
     {
         Id_Owner = owner,
         Id_Dish = dish_id,
         Mark = (int)mark,
         Description = text
     };
     context.dishreviews.Add(dr);
     context.SaveChanges();
     double average = (double)context.dishreviews.Where(r=>r.Id_Dish == dish_id).Average(r => r.Mark);
     dish d = GetDishById(dish_id);
     d.Raiting = Convert.ToInt32(Math.Round(average, 0));
     context.SaveChanges();
 }
Ejemplo n.º 2
0
 private void UpdateDishRating(dishreview dr)
 {
     var dishrev = context.dishreviews.Where(r => r.Id_Dish == dr.Id_Dish);
     dish d = GetDishById(dr.Id_Dish);
     if (dishrev.Count() != 0)
     {
         double average = (double)dishrev.Average(r => r.Mark);
         d.Raiting = Convert.ToInt32(Math.Round(average, 0));
     }
     else
     {
         d.Raiting = 0;
     }
     context.SaveChanges();
 }