Пример #1
0
        public FileStreamResult Weight(int timeFrame = 0)
        {
            var weightChart = new Chart
            {
                Width  = 600,
                Height = 300
            };
            var weights = _repository.GetWeightsByUser(User.Identity.Name);

            if (timeFrame > 0)
            {
                timeFrame = timeFrame * -1;
                var pastDate = DateTime.Today.AddMonths(timeFrame);
                weights = weights.Where(w => w.WeightDate > pastDate);
            }
            weights = weights.OrderBy(w => w.WeightDate);
            var builder = new DailyWeightChartBuilder(weights.ToList(), weightChart);

            builder.BuildChart();
            // Save the chart to a MemoryStream
            var imgStream = new MemoryStream();

            weightChart.SaveImage(imgStream, ChartImageFormat.Png);
            imgStream.Seek(0, SeekOrigin.Begin);

            // Return the contents of the Stream to the client
            return(File(imgStream, "image/png"));
        }
Пример #2
0
 public IEnumerable <DailyWeight> Get()
 {
     if (User.Identity.IsAuthenticated)
     {
         IQueryable <DailyWeight> results = _repository.GetWeightsByUser(User.Identity.Name);
         return(results.OrderByDescending(t => t.WeightDate).Take(50).ToList());
     }
     return(new DailyWeight[0]);
 }