Beispiel #1
0
        private async Task SwapWorkday(GetWorkingPeriodResponse request, WorkingPeriod workingPeriod)
        {
            var swapWorkDay = await _context.WorkDays.Include(wd => wd.WorkingPeriods).FirstOrDefaultAsync(wd => wd.Date == request.WorkingPeriod.StartTime.Date && wd.ContractId == request.UserContext.CurrentContract.Id);

            if (swapWorkDay == null)
            {
                _requiredCreationOfNewWorkDay = true;

                var newWorkDay = new WorkDay()
                {
                    ContractId  = request.UserContext.CurrentContract.Id,
                    Date        = request.WorkingPeriod.StartTime.Date,
                    WorkDayType = workingPeriod.StartTime.Date.ToWorkDayType(),
                };

                newWorkDay.RequiredHours = newWorkDay.GetRequiredHoursForDay(request.UserContext.CurrentContract.HoursPerWeek);
                workingPeriod.WorkDay    = newWorkDay;
                await _context.WorkDays.AddAsync(newWorkDay);

                return;
            }

            _swappedWorkDayId = swapWorkDay.Id;
            swapWorkDay.WorkingPeriods.Add(workingPeriod);
        }
Beispiel #2
0
        private WorkDay CreateWorkday(Contract currentContract)
        {
            if (currentContract == null)
            {
                throw new ArgumentNullException(nameof(Contract));
            }

            _workDayToday = new WorkDay {
                ContractId = currentContract.Id, Date = _now.Now.Date, WorkDayType = _now.Now.ToWorkDayType(), WorkingPeriods = new List <WorkingPeriod>()
            };
            _workDayToday.RequiredHours = _workDayToday.GetRequiredHoursForDay(currentContract.HoursPerWeek);
            _context.WorkDays.Add(_workDayToday);

            return(_workDayToday);
        }