Ejemplo n.º 1
0
        public IActionResult Index(int?id)
        {
            List <Shift> allShifts = _context.Shift.ToList();

            EmployeeModel employee = _context.EmployeeModel
                                     .Single(e => e.EMail == User.Identity.Name);

            if (id == null)
            {
                id = schedule._weekNumber;
            }

            List <Work> works            = _context.Works.Where(e => e.Employee == employee).Include(m => m.Employee).Include(s => s.Shift).ToList();
            var         workOverviewlist = new List <WorkOverview>();

            for (int i = 1; i <= 12; i++)
            {
                var workOverview = new WorkOverview
                {
                    Month = i
                };


                foreach (Work w in works)
                {
                    if (w.Shift.Start.Year == 2019 && w.Shift.Start.Month == i)
                    {
                        workOverview.AddHours((int)(w.Shift.End - w.Shift.Start).TotalHours);
                        workOverview.SubtractHours(w.Delay);
                        workOverview.AddHours(w.Overtime);
                    }
                }

                workOverviewlist.Add(workOverview);
            }

            schedule.currentWeek = (int)id;
            schedule.setWeek((int)id);
            schedule.makeSchedule();
            schedule.setShifts(allShifts);

            ViewData["workOverview"] = workOverviewlist;

            return(View(schedule));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GET: EmployeeModels
        /// </summary>
        /// <returns>Employee View</returns>
        public async Task<IActionResult> Index()
        {
            // return not found if ID not given.
            if (signInManager.IsSignedIn(User) && _context.EmployeeModel.Single(x => x.EMail == User.Identity.Name).Admin)
            {
                // create list of employees
                var employees = await _context.EmployeeModel.ToListAsync();

                // loop trough each employee and calculate worked hours
                foreach (EmployeeModel employee in employees)
                {
                    // get list of works associated with this employee
                    List<Work> works = _context.Works.Where(e => e.Employee == employee).Include(m => m.Employee).Include(s => s.Shift).ToList();

                    var worked = new WorkOverview(); // create work overview

                    // calculate worked hours bases on works hours
                    foreach (Work w in works)
                    {
                        //check if user is within this year
                        if (w.Shift.Start.Year == DateTime.Now.Year && w.Shift.Start.Month == DateTime.Now.Month)
                        {
                            worked.AddHours((int)(w.Shift.End - w.Shift.Start).TotalHours);
                            worked.SubtractHours(w.Delay);
                            worked.AddHours(w.Overtime);
                        }
                    }

                    // set WorkOverview to worked item
                    employee.Workoverview = worked;
                }

                return View(employees);
            }

            else
            {
                return Forbid(); // user is either not logged nor an admin, show forbidden page.
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// GET: EmployeeModels/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Employee View</returns>
        public async Task<IActionResult> Details(int? id)
        {
            // check if user is loggen in and user is an admin.
            if (signInManager.IsSignedIn(User) && _context.EmployeeModel.Single(x => x.EMail == User.Identity.Name).Admin)
            {
                // return not found if ID not given.
                if (id == null)
                {
                    return NotFound();
                }

                // Get employee model and include skills, functions and locations
                var employeeModel = await _context.EmployeeModel
                                            .Include(e => e.EmployeeSkills)
                                                .ThenInclude(e => e.Skill)
                                            .Include(f => f.EmployeeFunctions)
                                                .ThenInclude(f => f.Function)
                                            .Include(l => l.EmployeeLocations)
                                                .ThenInclude(l => l.Location)
                                            .AsNoTracking()
                                            .FirstOrDefaultAsync(m => m.ID == id);

                //add supervisor to viewbag
                ViewBag.Supervisor = _context.EmployeeModel.FirstOrDefault(s => s.ID == employeeModel.SupervisorID);

                // if employee model is not found, return not found.
                if (employeeModel == null)
                {
                    return NotFound();
                }

                // get all works associated with this employee
                List<Work> works = _context.Works.Where(e => e.Employee == employeeModel).Include(m => m.Employee).Include(s => s.Shift).ToList();
                var workOverviewlist = new List<WorkOverview>(); // create a list containing work overview


                // fill the list with 12 items (every item represents a month of the year).
                // a WorkOverview is created for every month of the year,
                // it will add an item to the list and calculate the users worked hours for that given month.
                for (int i = 1; i <= 12; i++)
                {
                    // create new work overview and set month to current itterations number
                    var workOverview = new WorkOverview
                    {
                        Month = i //set month to i
                    };

                    // go trough each users work and add total worked hours
                    // the worked hours calculated by adding and subtracting the delay and overtime
                    // this way the actual worked hours are shown
                    foreach (Work w in works)
                    {
                        //check if work is in current year and month
                        if (w.Shift.Start.Year == DateTime.Now.Year && w.Shift.Start.Month == i)
                        {
                            workOverview.AddHours((int)(w.Shift.End - w.Shift.Start).TotalHours);
                            workOverview.SubtractHours(w.Delay);
                            workOverview.AddHours(w.Overtime);
                        }
                    }

                    //add item to workOverViewList
                    workOverviewlist.Add(workOverview);
                }

                //add workOverViewList to the viewdata
                ViewData["workOverview"] = workOverviewlist;

                return View(employeeModel);
            } else
            {
                return Forbid(); // user is either not logged nor an admin, show forbidden page.
            }
        }
Ejemplo n.º 4
0
        public IActionResult Index(int?id)
        {
            if (User.Identity.IsAuthenticated)
            {
                EmployeeModel employee  = _context.EmployeeModel.Where(e => e.EMail == User.Identity.Name).Single();
                List <Shift>  allShifts = new List <Shift>();

                ICollection <Work> works = _context.Works
                                           .Where(e => e.Employee == employee)
                                           .Include(e => e.Employee)
                                           .Include(e => e.Shift)
                                           .AsNoTracking()
                                           .ToList();

                var workOverviewlist = new List <WorkOverview>();

                List <Shift> shifts = new List <Shift>();

                for (int i = 1; i <= 12; i++)
                {
                    var workOverview = new WorkOverview {
                        Month = i
                    };
                    foreach (Work w in works)
                    {
                        if (w.Shift.Start.Year == 2019 && w.Shift.Start.Month == i)
                        {
                            workOverview.AddHours((int)(w.Shift.End - w.Shift.Start).TotalHours);
                            workOverview.SubtractHours(w.Delay);
                            workOverview.AddHours(w.Overtime);
                        }
                    }
                    workOverviewlist.Add(workOverview);
                }

                foreach (Work w in works)
                {
                    allShifts.Add(w.Shift);
                }


                if (id == null)
                {
                    id = schedule._weekNumber;
                }


                schedule.currentWeek = (int)id;
                schedule.setWeek((int)id);
                schedule.makeSchedule();
                schedule.setShifts(allShifts);

                ViewData["workOverview"] = workOverviewlist;

                return(View(schedule));
            }
            else
            {
                return(Redirect("/Identity/Account/Login"));
            }
        }