Exemple #1
0
        // PUT api/mEndOfDayReport/5
        public IHttpActionResult PutEndOfDayReport(long id, EndOfDayReport endOfDayReport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != endOfDayReport.Id)
            {
                return(BadRequest());
            }

            try
            {
                _endOfDayReportService.UpdateEndOfDayReport(endOfDayReport);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EndOfDayReportExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public async Task <IHttpActionResult> GetEndOfDayReport(long id)
        {
            EndOfDayReport endOfDayReport = await _endOfDayReportService.FindEndOfDayReport(id);

            if (endOfDayReport == null)
            {
                return(NotFound());
            }

            return(Ok(endOfDayReport));
        }
        public async Task <long> CreateEndOfDayReport(EndOfDayReport report)
        {
            _endOfDayReportRepository.Create(report);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(report);

            await _unit.Commit();

            return(report.Id);
        }
        public EndOfDayReport CalculateEndOfDayReport(DateTime date, User user)
        {
            #region totalling
            var activities = _activityRepository.GetUserActivitiesByDay(user.Id, date);
            if (activities.Count() == 0)
            {
                var r = new EndOfDayReport()
                {
                    TotalDistance = 0,
                    TotalDuration = 0,
                    TotalSteps    = 0,
                    UserId        = user.Id,
                    Date          = date
                };
                return(r);
            }

            var totals = from a in activities
                         group a by 1
                         into act
                         select new
            {
                totalDuration = act.Sum(x => x.Duration),
                totalDistance = act.Sum(x => x.Distance),
                totalSteps    = act.Sum(x => x.Steps)
            };
            totals = totals.ToArray();

            #endregion totalling

            var report = new EndOfDayReport()
            {
                TotalDistance = totals.Single().totalDistance,
                TotalDuration = totals.Single().totalDuration,
                TotalSteps    = totals.Single().totalSteps,
                UserId        = user.Id,
                Date          = date
            };
            return(report);
        }
 public async Task UpdateEndOfDayReport(EndOfDayReport report)
 {
     _endOfDayReportRepository.Update(report);
     await _unit.Commit();
 }