public IHttpActionResult GetTopPerformances() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var topPerformances = db.TopPerformances().ToList(); var monthPerformance = topPerformances.OrderByDescending(x => x.MonthPoints).Take(3).ToList(); var pointsInWeek = topPerformances.OrderByDescending(x => x.WeekPoints).FirstOrDefault(); var pointsinaDay = topPerformances.OrderByDescending(x => x.DayPoints).FirstOrDefault(); if (pointsinaDay != null && pointsInWeek != null) { var performerOftheDay = topPerformances.Where(x => x.DayPoints == pointsinaDay.DayPoints).ToList(); var performerOftheWeek = topPerformances.Where(x => x.WeekPoints == pointsInWeek.WeekPoints).ToList(); return(Content(HttpStatusCode.OK, new { topPerformances, monthPerformance, pointsinaDay, pointsInWeek, performerOftheDay, performerOftheWeek })); } else if (pointsInWeek != null) { var performerOftheWeek = topPerformances.Where(x => x.WeekPoints == pointsInWeek.WeekPoints).ToList(); return(Content(HttpStatusCode.OK, new { topPerformances, monthPerformance, pointsinaDay, pointsInWeek })); } else if (pointsinaDay != null) { var performerOftheDay = topPerformances.Where(x => x.DayPoints == x.DayPoints).ToList(); return(Content(HttpStatusCode.OK, new { topPerformances, monthPerformance, pointsinaDay, pointsInWeek, performerOftheDay })); } else { return(Content(HttpStatusCode.OK, new { topPerformances, monthPerformance, pointsinaDay, pointsInWeek })); } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An Error occured,please try again later")); } }