Beispiel #1
0
 /// <summary>
 /// Helper function for summing DailyEnergy could be later replaced with automapper
 /// </summary>
 private DailyEnergy mergeDailyEnergy(DailyEnergy dailyEnergy, DailyEnergy oldDEnergy)
 {
     dailyEnergy.Body     += oldDEnergy.Body;
     dailyEnergy.Emotions += oldDEnergy.Emotions;
     dailyEnergy.Mind     += oldDEnergy.Mind;
     dailyEnergy.Soul     += oldDEnergy.Soul;
     return(dailyEnergy);
 }
 /// <summary>
 /// Helper function for summing DailyEnergy could be later replaced with automapper
 /// </summary>
 private DailyEnergy mergeDailyEnergy(DailyEnergy dailyEnergy, DailyEnergy oldDEnergy)
 {
     dailyEnergy.body     += oldDEnergy.body;
     dailyEnergy.emotions += oldDEnergy.emotions;
     dailyEnergy.mind     += oldDEnergy.mind;
     dailyEnergy.soul     += oldDEnergy.soul;
     return(dailyEnergy);
 }
 public Task createOrUpdateAsync(DailyEnergy dailyEnergy)
 {
     if (dailyEnergy.id != null)
     {
         return(updateAsync(dailyEnergy.id, dailyEnergy.validate()));
     }
     return(createAsync(dailyEnergy.validate()));
 }
Beispiel #4
0
        private async Task manageEnergyAsync(Dictionary <STATS, int> wages, TimeSpend timeSpend)
        {
            DailyEnergy dailyEnergy = calculateEnergy(wages, timeSpend);

            dailyEnergy.UserId = timeSpend.UserId;
            dailyEnergy.Date   = DateTime.UtcNow.Date;
            _logger.LogInformation(dailyEnergy.ToString());
            await _dailyEnergyService.CreateOrAddAsync(dailyEnergy);
        }
Beispiel #5
0
        private DailyEnergy updateEnergiesWithWages(Del op, DailyEnergy dailyEnergy, Dictionary <STATS, int> wages, int duration)
        {
            int sum = wages.Sum(x => x.Value);

            dailyEnergy.body     = (int)op(dailyEnergy.body, duration * wages.GetValueOrDefault(STATS.STRENGTH) / sum);
            dailyEnergy.soul     = (int)op(dailyEnergy.soul, duration * wages.GetValueOrDefault(STATS.FLUENCY) / sum);
            dailyEnergy.emotions = (int)op(dailyEnergy.emotions, duration * wages.GetValueOrDefault(STATS.CREATIVITY) / sum);
            dailyEnergy.mind     = (int)op(dailyEnergy.mind, duration * wages.GetValueOrDefault(STATS.INTELLIGENCE) / sum);
            return(dailyEnergy);
        }
Beispiel #6
0
        private async Task manageEnergyAsync(Del op, Dictionary <STATS, int> wages, ProjectLog projectLog)
        {
            DailyEnergy dailyEnergy = await _dailyEnergyRepository.getByDateAndUserIdAsync(projectLog.dateCreated, projectLog.userId);

            if (dailyEnergy == null)
            {
                dailyEnergy = new DailyEnergy().init();
            }
            dailyEnergy.userId      = projectLog.userId;
            dailyEnergy.dateCreated = projectLog.dateCreated.Date;
            dailyEnergy             = calculateAndUpdateEnergy(op, dailyEnergy, wages, projectLog);
            if (dailyEnergy != null)
            {
                await _dailyEnergyRepository.createOrUpdateAsync(dailyEnergy);
            }
        }
Beispiel #7
0
        private DailyEnergy calculateAndUpdateEnergy(Del op, DailyEnergy dailyEnergy, Dictionary <STATS, int> wages, ProjectLog projectLog)
        {
            switch (projectLog.type)
            {
            case (PROJECT_TYPE.ENERGY):
                return(updateEnergiesWithWages(op, dailyEnergy, wages, projectLog.timeSpend >> 1));

            case (PROJECT_TYPE.STAT):
                return(updateEnergiesWithWages(op, dailyEnergy, wages, projectLog.timeSpend * -1));

            case (PROJECT_TYPE.BREAK):
                return(updateEnergiesWithWages(op, dailyEnergy, wages, projectLog.timeSpend >> 1));

            default:
                return(null);
            }
        }
Beispiel #8
0
        public async Task <DailyEnergy> CreateOrAddAsync(DailyEnergy dailyEnergy)
        {
            try
            {
                var oldDEnergy = await _DailyEnergy.Find(o => o.Date == dailyEnergy.Date && o.UserId == dailyEnergy.UserId).SingleOrDefaultAsync();

                if (null == oldDEnergy)
                {//Create
                    await _DailyEnergy.InsertOneAsync(mergeDailyEnergy(dailyEnergy, new DailyEnergy().init()).validate());
                }
                else
                {//Update   //TODO use mapper for adding
                    dailyEnergy.Id = oldDEnergy.Id;
                    dailyEnergy    = mergeDailyEnergy(dailyEnergy, oldDEnergy);
                    await UpdateAsync(dailyEnergy.validate());
                }
                return(dailyEnergy);
            }
            catch (Exception e)
            {
                _logger.LogError("Error cached in DailyEnergyServices CreateOrUpdateAsync {error}", e);
                return(null);
            }
        }
Beispiel #9
0
 public void Update(DailyEnergy dailyEnergy) =>
 _DailyEnergy.ReplaceOne(o => o.Id == dailyEnergy.Id, dailyEnergy);
Beispiel #10
0
 public DailyEnergy Create(DailyEnergy DailyEnergy)
 {
     _DailyEnergy.InsertOne(DailyEnergy);
     return(DailyEnergy);
 }
Beispiel #11
0
 public void Remove(DailyEnergy dailyEnergy) =>
 _DailyEnergy.DeleteOne(o => o.Id == dailyEnergy.Id);
Beispiel #12
0
 public async Task UpdateAsync(DailyEnergy dailyEnergy) =>
 await _DailyEnergy.ReplaceOneAsync(o => o.Id == dailyEnergy.Id, dailyEnergy);
 public Task deleteByDailyEnergyAsync(DailyEnergy DailyEnergyIn)
 {
     return(_DailyEnergies.DeleteOneAsync(DailyEnergy => DailyEnergy.id == DailyEnergyIn.id));
 }
 public Task updateAsync(string id, DailyEnergy newDailyEnergy)
 {
     return(_DailyEnergies.ReplaceOneAsync(DailyEnergy => DailyEnergy.id == id, newDailyEnergy));
 }
 public Task createAsync(DailyEnergy DailyEnergy)
 {
     return(_DailyEnergies.InsertOneAsync(DailyEnergy.validate()));
 }