Beispiel #1
0
        public long CreateStatistics(long totalSeconds, int entryCount, int userId, long periodId)
        {
            if (this._identityRepository.Get(userId) == null)
            {
                throw new ApplicationException(string.Format("User doesn't exists with id = {0}", userId));
            }
            if (this._periodRepository.Get(periodId) == null)
            {
                throw new ApplicationException(string.Format("User doesn't exists with id = {0}", periodId));
            }
            if (this._repository.Query(statistic => statistic.PeriodId == periodId && statistic.IdentityId == userId).Any())
            {
                throw new ApplicationException(string.Format("Statistic for user with Id={0} and Period Id={1} already exists", userId, periodId));
            }

            var stats = new WasteStatistic {
                PeriodId = periodId, EntryCount = entryCount, IdentityId = userId, TimeSumInSecond = totalSeconds
            };

            return(this._repository.Create(stats));
        }
Beispiel #2
0
 public void UpdateStats(WasteStatistic statsToUpdate)
 {
     this._repository.Update(statsToUpdate);
 }