예제 #1
0
        public async Task AddTimeEntryToHourPoints(Guid userId, TimeEntry timeEntry)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsWithTimeEntriesByDateAndUser(timeEntry.DateHourPointed, userId);

            HourPointConfigurations configurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            if (hourPoints is null)
            {
                hourPoints = new HourPoints(timeEntry.DateHourPointed.Date, userId);
                hourPoints.AddTimeEntry(timeEntry, configurations);
                _hourPointsRepository.AddHourPoints(hourPoints);
            }
            else
            {
                if (hourPoints.HasTimeEntry(timeEntry))
                {
                    return;
                }

                hourPoints.AddTimeEntry(timeEntry, configurations);
                _hourPointsRepository.UpdateHourPoints(hourPoints);
            }

            _hourPointsRepository.AddTimeEntry(timeEntry);
            await _hourPointsRepository.Commit();
        }
예제 #2
0
        public async Task <IActionResult> DeleteHourPoints(Guid hourPointsId)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(hourPointsId);

            _hourPointsRepository.RemoveHourPoints(hourPoints);
            await _hourPointsRepository.Commit();

            return(RedirectToAction(nameof(Index)));
        }
예제 #3
0
        public async Task RecalculeExtraTimeAndMissingTime(Guid hourPointsId, Guid userId)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(hourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.CalculateExtraTime(hourPointConfigurations);
            hourPoints.CalculateMissingTime(hourPointConfigurations);

            _hourPointsRepository.UpdateHourPoints(hourPoints);
            await _hourPointsRepository.Commit();
        }
예제 #4
0
        public async Task UpdateTimeEntryDateHourPointed(Guid hourPointsId, Guid timeEntryId, Guid userId, DateTime newDateHourPointed)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(hourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.ChangeTimeEntryDateHourPointed(newDateHourPointed, timeEntryId, hourPointConfigurations);

            _hourPointsRepository.UpdateHourPoints(hourPoints);

            await _hourPointsRepository.Commit();
        }
예제 #5
0
        public async Task AutoGenerateHourPointForTodayWithTimeEntries(Guid userId)
        {
            if (await _hourPointsRepository.ExistsHourPointsToDateAndUser(DateTime.Now, userId))
            {
                return;
            }

            HourPointConfigurations configurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            HourPoints hourPoints = HourPoints.CreateWithAutoGeneratedTimeEntries(userId, configurations);

            _hourPointsRepository.AddHourPoints(hourPoints);
            await _hourPointsRepository.Commit();
        }
예제 #6
0
        public async Task RemoveTimeEntryFromHourPoints(Guid userId, Guid timeEntryId)
        {
            TimeEntry timeEntry = await _hourPointsRepository.GetTimeEntryById(timeEntryId);

            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(timeEntry.HourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.RemoveTimeEntry(timeEntry, hourPointConfigurations);

            _hourPointsRepository.RemoveTimeEntry(timeEntry);

            if (!hourPoints.TimeEntries.Any())
            {
                _hourPointsRepository.RemoveHourPoints(hourPoints);
            }
            else
            {
                _hourPointsRepository.UpdateHourPoints(hourPoints);
            }

            await _hourPointsRepository.Commit();
        }
예제 #7
0
 public void UpdateHourPoints(HourPoints hourPoints)
 {
     _context.HourPoints.Update(hourPoints);
 }
예제 #8
0
 public void RemoveHourPoints(HourPoints hourPoints)
 {
     _context.HourPoints.Remove(hourPoints);
 }
예제 #9
0
 public void AddHourPoints(HourPoints hourPoints)
 {
     _context.HourPoints.Add(hourPoints);
 }