Ejemplo n.º 1
0
        public async Task <Result> ModifyJobTaskCombo(int employeeId, int weekId, int newTaskId, int newJobId, int oldTaskId, int oldJobId)
        {
            var timeEntries = await timeService.GetAsync(weekId, employeeId);

            var oldEntries      = timeEntries.Where(x => x.JobId == oldJobId && x.JobTaskId == oldTaskId).ToList();
            var existingEntries = timeEntries.Where(x => x.JobId == newJobId && x.JobTaskId == newTaskId).ToList();

            foreach (var item in oldEntries.GroupBy(x => x.Date.DayOfWeek).Select(z => new { DayOfWeek = z.Key, entry = z.First() }))
            {
                var match = existingEntries.FirstOrDefault(x => x.Date.DayOfWeek == item.DayOfWeek);
                if (match != null)
                {
                    match.Hours         += item.entry.Hours;
                    match.OvertimeHours += item.entry.OvertimeHours;
                    await timeService.SaveAsync(employeeId, match);
                }
                else
                {
                    await timeService.SaveAsync(employeeId, new TimeEntryDTO()
                    {
                        Date          = item.entry.Date,
                        EmployeeId    = item.entry.EmployeeId,
                        Hours         = item.entry.Hours,
                        JobId         = newJobId,
                        JobTaskId     = newTaskId,
                        OvertimeHours = item.entry.OvertimeHours,
                        WeekId        = weekId
                    });
                }
            }
            await timeService.DeleteAllEntries(weekId, oldTaskId, oldJobId, employeeId);

            return(new Result(true));
        }
Ejemplo n.º 2
0
        public async Task <Result> RemoveRow(int employeeId, int weekId, int taskId, int jobId)
        {
            await timeService.DeleteAllEntries(weekId, taskId, jobId, employeeId);

            return(new Result(true));
        }