Esempio n. 1
0
        public async Task SaveAsync(int employeeId, TimeEntryDTO entry)
        {
            using (var db = _contextFactory.CreateDb())
            {
                var forUpdate = await db.TimeEntries.SingleOrDefaultAsync(x => x.Date == entry.Date && x.EmployeeId == employeeId && x.TaskId == entry.JobTaskId && x.JobId == entry.JobId);

                if (forUpdate == null)
                {
                    forUpdate = MapToEF(employeeId, entry);
                    db.TimeEntries.Add(forUpdate);
                }
                forUpdate.Hours         = entry.Hours;
                forUpdate.OvertimeHours = entry.OvertimeHours;
                await db.SaveChangesAsync();
            }
        }
Esempio n. 2
0
        private TimeEntryDTO CreateDTO(WeekDTO week, int SelectedTaskId, int SelectedJobId,
                                       int employeeId, DayOfWeek dayOfWeek)
        {
            var candidate = week.WeekStart;

            while (candidate.DayOfWeek != dayOfWeek)
            {
                candidate = candidate.AddDays(1);
            }
            var dto = new TimeEntryDTO()
            {
                Date          = candidate,
                EmployeeId    = employeeId,
                Hours         = 0,
                OvertimeHours = 0,
                JobId         = SelectedJobId,
                JobTaskId     = SelectedTaskId,
                TimeEntryId   = 0,
                WeekId        = week.WeekId.Value
            };

            return(dto);
        }