// GET: HolidayRequests/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var holidayRequest = await _context.HolidayRequests.Include(x => x.Employee).Where(x => x.HolidayRequestId == id).FirstOrDefaultAsync();

            if (holidayRequest.Employee.UserName != User.Identity.Name)
            {
                return(Unauthorized());
            }
            if (holidayRequest == null)
            {
                return(NotFound());
            }

            var user = await _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefaultAsync();

            var editViewModel = new HolidayRequestCreateEditViewModel();

            editViewModel.NoOfDaysLeft     = user.CurentYearHolidaysNumber.Value - HolidayRequestService.SumOfEmployeeDays(await GetUsersHolidays());
            editViewModel.HolidayRequestId = holidayRequest.HolidayRequestId;
            editViewModel.StartDate        = holidayRequest.StartDate;
            editViewModel.EndDate          = holidayRequest.EndDate;
            editViewModel.Days             = holidayRequest.NoOfDays;

            return(View(editViewModel));
        }
        // GET: HolidayRequests/Create
        public async Task <IActionResult> Create()
        {
            var createViewModel = new HolidayRequestCreateEditViewModel();
            var user            = await _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefaultAsync();

            createViewModel.NoOfDaysLeft = user.CurentYearHolidaysNumber.Value - HolidayRequestService.SumOfEmployeeDays(await GetUsersHolidays());
            createViewModel.StartDate    = DateTime.Now.Date;
            createViewModel.EndDate      = DateTime.Now.Date;

            return(View(createViewModel));
        }
        // GET: HolidayRequests
        public async Task <IActionResult> Index(string sortOrder)
        {
            ViewBag.StartSortParam      = String.IsNullOrEmpty(sortOrder) ? "startDate" : "";
            ViewBag.EndSortParam        = sortOrder == "EndDate" ? "Enddate_desc" : "EndDate";
            ViewBag.TypeSortParam       = sortOrder == "Type" ? "Type_desc" : "Type";
            ViewBag.StatusSortParam     = sortOrder == "Status" ? "Status_desc" : "Status";
            ViewBag.ModifiedOnSortParam = sortOrder == "ModifiedOn" ? "ModifiedOn_desc" : "ModifiedOn";
            ViewBag.ApproverSortParam   = sortOrder == "Approver" ? "Approver_desc" : "Approver";
            ViewBag.DaysSortParam       = sortOrder == "Days" ? "Days_desc" : "Days";

            var holidaysViewModel = new HolidayPageViewModel();

            holidaysViewModel.EmloyeeFullName       = _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault().FullName;
            holidaysViewModel.EmployeeTotalNoOfDays = _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault().CurentYearHolidaysNumber;
            var holidays = await GetUsersHolidays();

            if (holidaysViewModel.EmployeeTotalNoOfDays != null)
            {
                holidaysViewModel.EmployeeTotalDaysLeft = holidaysViewModel.EmployeeTotalNoOfDays.Value - HolidayRequestService.SumOfEmployeeDays(holidays);
            }
            else
            {
                holidaysViewModel.EmployeeTotalDaysLeft = 0;
            }

            holidaysViewModel.Holidays = holidays;

            switch (sortOrder)
            {
            case "startDate":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.StartDate).ToList();
                break;

            case "Enddate_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.EndDate).ToList();
                break;

            case "EndDate":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.EndDate).ToList();
                break;

            case "Type_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.Type).ToList();
                break;

            case "Type":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.Type).ToList();
                break;

            case "Status_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.Type).ToList();
                break;

            case "Status":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.Type).ToList();
                break;

            case "ModifiedOn_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.ModifiedDate).ToList();
                break;

            case "ModifiedOn":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.ModifiedDate).ToList();
                break;

            case "Approver_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.Approver.FullName).ToList();
                break;

            case "Approver":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.Approver.FullName).ToList();
                break;

            case "Days_desc":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.NoOfDays).ToList();
                break;

            case "Days":
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderBy(s => s.NoOfDays).ToList();
                break;

            default:
                holidaysViewModel.Holidays = holidaysViewModel.Holidays.OrderByDescending(s => s.StartDate).ToList();
                break;
            }
            return(View(holidaysViewModel));
        }