Exemple #1
0
        public async Task <IActionResult> GetCaloriesOverTime([FromQuery] int athleteId, [FromQuery] string startDate, [FromQuery] string endDate)
        {
            var response = new SingleModelResponse <double>()
                           as ISingleModelResponse <double>;

            try
            {
                if ((athleteId.ToString()) == null &&
                    (startDate.ToString()) == null &&
                    (endDate.ToString()) == null)
                {
                    throw new Exception("All parameters missing");
                }
                else
                {
                    string exepMess = "";
                    if ((athleteId.ToString()) == null)
                    {
                        exepMess += "Athlete Id Missing\n";
                    }
                    if ((startDate.ToString()) == null)
                    {
                        exepMess += "Start Date missing\n";
                    }
                    if ((endDate.ToString()) == null)
                    {
                        exepMess += "End Date missing";
                    }
                    if (exepMess != "")
                    {
                        throw new Exception(exepMess);
                    }
                }


                response.Model = await Task.Run(() =>
                {
                    double calories = -1;
                    calories        = _context.GetCaloriesOverTime(athleteId, startDate, endDate);
                    if (calories < 0)
                    {
                        throw new Exception("Run does not exist");
                    }
                    return(calories);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }