Ejemplo n.º 1
0
        public async Task <EmployeeTimesheet> GetTimesheetByUserID(UserDateDto userDate)
        {
            EmployeeTimesheet empSheet = null;
            TimesheetRow      sheetRow = null;
            var      teamId            = 0;
            DateTime fromDate          = userDate.Date.AddDays(-1);
            DateTime toDate            = userDate.Date.AddDays(6);

            using (var context = new DatabaseContext())
            {
                teamId = context.Employee.Where(x => x.BSIPLid == userDate.UserId).Select(x => x.TeamId).FirstOrDefault <int>();
                var taskTeams = await context.TaskTeam.Where(x => x.TeamId == teamId).Include(x => x.Task).ToListAsync <TaskTeam>();

                var taskGroup = (from t in taskTeams
                                 select new EmployeeTask {
                    Id = t.TaskId, Name = t.Task.Name
                }).ToList();

                var tsheet1 = await(context.TimeSheet.Include(x => x.Task).Where(t => t.EmployeeId == userDate.UserId && t.Date >= fromDate && t.Date <= toDate)
                                    .ToListAsync());
                decimal workHours = 0;
                empSheet = new EmployeeTimesheet()
                {
                    EmployeeId    = userDate.UserId,
                    TeamId        = teamId,
                    TimesheetRows = new List <TimesheetRow>()
                };

                //select max data rom tsheets
                DateTime maxdate = new DateTime();
                if (tsheet1.Count > 0)
                {
                    maxdate = tsheet1[0].Date;
                }

                foreach (Timesheet t in tsheet1)
                {
                    if (t.Date > maxdate)
                    {
                        maxdate = t.Date;
                    }
                }

                //Prepare Colmns and Rows
                //Group by TaskIds
                //Loop through Tasks
                int    ctr      = 1;
                string taskName = string.Empty;
                foreach (var task in taskGroup)
                {
                    List <TimesheetColumn> cols = null;
                    //Loop through days
                    //get the actual days with dates
                    cols = new List <TimesheetColumn>();
                    var newDate = new DateTime(userDate.Date.Year, userDate.Date.Month, userDate.Date.Day, 0, 0, 0, DateTimeKind.Utc);
                    while (newDate.Date <= toDate.Date && newDate.Date <= maxdate.Date)
                    {
                        if (newDate.Date >= fromDate.Date)
                        {
                            workHours = (tsheet1 == null || tsheet1.Count == 0) ? 0 : tsheet1.Where(x => DateTime.Compare(x.Date.Date, newDate.Date) == 0 && x.TaskId == task.Id).FirstOrDefault().Hour;
                            var timesheetCol = new TimesheetColumn()
                            {
                                id         = 1,
                                taskId     = task.Id,
                                employeeId = userDate.UserId, //get task name
                                date       = newDate,
                                hours      = workHours
                                             //approved =
                            };
                            cols.Add(timesheetCol);
                            newDate = newDate.AddDays(1);
                        }
                    }

                    taskName = (tsheet1 == null || tsheet1.Count == 0) ? task.Name : tsheet1.Where(x => x.TaskId == task.Id).FirstOrDefault().Task.Name;
                    sheetRow = new TimesheetRow()
                    {
                        id               = ctr,
                        taskId           = task.Id,
                        taskName         = taskName,
                        timesheetColumns = cols,
                        totalHours       = 0
                    };

                    empSheet.TimesheetRows.Add(sheetRow);
                    ctr++;
                }
            }

            return(empSheet);
        }
Ejemplo n.º 2
0
 private void LogChange(EmployeeTimesheet entry)
 {
     // For deletions, values are not changed, so all nullable fields are null
     EmployeeTimesheetChangeLog.Add(entry.Id, SessionManager.ActiveEmployee.Id, null,
                                    null, null, null, null);
 }
Ejemplo n.º 3
0
 private void ClockIn()
 {
     EmployeeTimesheet.Add(ActiveEmployee.Id, ActiveJob.Id);
     Window.GetWindow(this).Close();
 }