protected void submitHolidayRequest(object sender, EventArgs e)
        {
            DateTime startDate   = startDateCalendar.SelectedDate;
            DateTime endDate     = endDateCalendar.SelectedDate;
            int      workingDays = GeneralUtils.CalculateWorkingDays(startDate, endDate);

            startDate = GeneralUtils.simplifyStartDate(startDate);
            endDate   = GeneralUtils.simplifyEndDate(endDate);
            if (workingDays == 0)
            {
                displayHolidaySummary("You selected weekend days, no need for holiday allowance", GeneralUtils.DANGER_COLOR);
                return;
            }
            else if (workingDays > GeneralUtils.MAX_POSSIBLE_HOLIDAY)
            {
                displayHolidaySummary("Too many days selected, it exceeds the maximum allowance", GeneralUtils.DANGER_COLOR);
                return;
            }
            if (startDate.Year > DateTime.Now.Year || endDate.Year > DateTime.Now.Year)
            {
                displayHolidaySummary("Sorry, not accepting holiday requests for next year yet", GeneralUtils.DANGER_COLOR);
                return;
            }
            try
            {
                using (HBSModel _entity = new HBSModel())
                {
                    int userId = (int)Session["userId"];

                    HolidayRequest holidayRequest = new HolidayRequest()
                    {
                        StartDate    = startDate,
                        EndDate      = endDate,
                        UserID       = userId,
                        NumberOfDays = workingDays
                    };
                    var usr = _entity.Users.Find(userId);

                    if (usr.HolidayRequests.Where(x => x.StatusRequest.Status == GeneralUtils.APPROVED ||
                                                  x.StatusRequest.Status == GeneralUtils.PENDING)
                        .Any(x => GeneralUtils.isOverlappingHoliday(x, holidayRequest)))
                    {
                        displayHolidaySummary("There is an overlap with your current pending or approved requests", GeneralUtils.DANGER_COLOR);
                        return;
                    }
                    holidayRequest.RequestStatusID = _entity.StatusRequests
                                                     .FirstOrDefault(status => status.Status == GeneralUtils.PENDING).ID;
                    holidayRequest.ConstraintsBroken = new ConstraintChecking(usr, holidayRequest).getBrokenConstraints();
                    holidayRequest.DaysPeakTime      = PrioritiseRequests
                                                       .daysFallPeakTimesCount(holidayRequest.StartDate, holidayRequest.EndDate);
                    _entity.HolidayRequests.Add(holidayRequest);
                    _entity.SaveChanges();
                    Response.Redirect("/EmployeeHome?HolidayRequest=Success");
                }
            }
            catch
            {
                Response.Write("Server encountered an issue while submitting your request");
            }
        }
        protected void verifySelectedDate(object sender, EventArgs e)
        {
            Calendar calendar = (Calendar)sender;

            if (calendar.ID == startDateCalendar.ID)
            {
                if (startDateCalendar.SelectedDate < DateTime.Today.AddDays(5))
                {
                    startDateCalendar.SelectedDates.Clear();
                    displayHolidaySummary("Please select a start date for at least 5 days in future.", GeneralUtils.DANGER_COLOR);
                }
                endDateCalendar.SelectedDates.Clear();
                if (startDateCalendar.SelectedDate.Month > DateTime.Now.Month)
                {
                    endDateCalendar.TodaysDate = startDateCalendar.SelectedDate.AddDays(1);
                }
                submitButton.BackColor   = ColorTranslator.FromHtml(GeneralUtils.DANGER_COLOR);
                submitButton.BorderColor = ColorTranslator.FromHtml(GeneralUtils.DANGER_COLOR);
                submitButton.Enabled     = false;
            }
            else
            {
                if (startDateCalendar.SelectedDate < DateTime.Today)
                {
                    endDateCalendar.SelectedDates.Clear();
                    displayHolidaySummary("Please select a start date first.", GeneralUtils.DANGER_COLOR);
                    return;
                }

                if (endDateCalendar.SelectedDate < startDateCalendar.SelectedDate)
                {
                    endDateCalendar.SelectedDates.Clear();
                    displayHolidaySummary("End date must come after start date", GeneralUtils.DANGER_COLOR);
                }
                else
                {
                    DateTime startDate   = startDateCalendar.SelectedDate;
                    DateTime endDate     = endDateCalendar.SelectedDate;
                    int      workingDays = GeneralUtils.CalculateWorkingDays(startDate, endDate);
                    if (workingDays == 0)
                    {
                        displayHolidaySummary("You selected weekend days, no need for holiday allowance", GeneralUtils.WARNING_COLOR);
                    }
                    else if (workingDays > GeneralUtils.MAX_POSSIBLE_HOLIDAY)
                    {
                        displayHolidaySummary("Too many days selected, it exceeds the maximum allowance", GeneralUtils.DANGER_COLOR);
                    }
                    else
                    {
                        displayHolidaySummary("You requested " + workingDays + " day(s) of holiday allowance from " +
                                              startDate.ToShortDateString() + " to " +
                                              endDate.ToShortDateString() + ". Please submit if you are satisfied with your selection", GeneralUtils.SUCCESS_COLOR);
                        submitButton.BackColor   = ColorTranslator.FromHtml(GeneralUtils.SUCCESS_COLOR);
                        submitButton.BorderColor = ColorTranslator.FromHtml(GeneralUtils.SUCCESS_COLOR);
                        submitButton.Enabled     = true;
                    }
                }
            }
        }
 private void onSelectedEndDateChanged(object sender, SelectionChangedEventArgs e)
 {
     if (endDateCalendar.SelectedDate > startDateCalendar.SelectedDate)
     {
         DateTime startDate   = (DateTime)startDateCalendar.SelectedDate;
         DateTime endDate     = (DateTime)endDateCalendar.SelectedDate;
         int      workingDays = GeneralUtils.CalculateWorkingDays(startDate, endDate);
         errorBlock.Visibility = Visibility.Visible;
         errorBlock.Text       = "You are asking for " + workingDays + " day(s) of holiday allowance.";
         errorBlock.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF0E8B19"));
     }
 }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     errorBlock.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFF90505"));
     if (endDateCalendar.SelectedDate < startDateCalendar.SelectedDate)
     {
         DateTime dateTime = (DateTime)startDateCalendar.SelectedDate;
         errorBlock.Visibility        = Visibility.Visible;
         endDateCalendar.SelectedDate = dateTime.AddDays(1);
         errorBlock.Foreground        = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFF90505"));
         errorBlock.Text = "End date must come after start date";
     }
     else
     {
         errorBlock.Visibility = Visibility.Visible;
         DateTime startDate   = (DateTime)startDateCalendar.SelectedDate;
         DateTime endDate     = (DateTime)endDateCalendar.SelectedDate;
         int      workingDays = GeneralUtils.CalculateWorkingDays(startDate, endDate);
         if (startDate.Year > DateTime.Now.Year || endDate.Year > DateTime.Now.Year)
         {
             errorBlock.Text = "Sorry, not accepting holiday requests for next year yer";
             return;
         }
         if (workingDays == 0)
         {
             errorBlock.Text = "You selected weekend days, no need for holiday allowance";
         }
         else if (workingDays > GeneralUtils.MAX_POSSIBLE_HOLIDAY)
         {
             errorBlock.Text = "Too many days selected, it exceeds the maximum allowance";
         }
         else
         {
             try
             {
                 this.Cursor = Cursors.Wait;
                 startDate   = GeneralUtils.simplifyStartDate(startDate);
                 endDate     = GeneralUtils.simplifyEndDate(endDate);
                 string username = (string)Application.Current.Resources["username"];
                 string password = (string)Application.Current.Resources["password"];
                 int    res      = client.HolidayRequest(startDate, endDate, workingDays, username, password);
                 this.Cursor = Cursors.Arrow;
                 if (res == 1)
                 {
                     errorBlock.Text       = "Holiday Request Submitted";
                     errorBlock.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF0E8B19"));
                 }
                 else if (res == -4)
                 {
                     errorBlock.Text = "Invalid parameters, please double check your selection";
                 }
                 else
                 {
                     errorBlock.Text = "Request failed. Please logout and try again later";
                 }
             }
             catch
             {
                 errorBlock.Text = "Request failed, please try again later";
             }
         }
     }
 }
 public static void AddHolidayRequests()
 {
     using (HBSModel _entity = new HBSModel())
     {
         if (_entity.HolidayRequests.Count() < 2)
         {
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 8, 7),
                 EndDate           = new DateTime(2020, 8, 21),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 8, 7), new DateTime(2020, 8, 21)),
                 RequestStatusID   = 1,
                 UserID            = 5,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 4, 6),
                 EndDate           = new DateTime(2020, 4, 15),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 4, 6), new DateTime(2020, 4, 15)),
                 RequestStatusID   = 1,
                 UserID            = 7,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 8, 7),
                 EndDate           = new DateTime(2020, 8, 21),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 8, 7), new DateTime(2020, 8, 21)),
                 RequestStatusID   = 1,
                 UserID            = 8,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 8, 7),
                 EndDate           = new DateTime(2020, 8, 21),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 8, 7), new DateTime(2020, 8, 21)),
                 RequestStatusID   = 1,
                 UserID            = 11,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 7, 7),
                 EndDate           = new DateTime(2020, 7, 17),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 7, 7), new DateTime(2020, 7, 17)),
                 RequestStatusID   = 1,
                 UserID            = 12,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 8, 2),
                 EndDate           = new DateTime(2020, 8, 13),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 8, 2), new DateTime(2020, 8, 13)),
                 RequestStatusID   = 1,
                 UserID            = 13,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 9, 7),
                 EndDate           = new DateTime(2020, 9, 11),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 9, 7), new DateTime(2020, 9, 11)),
                 RequestStatusID   = 1,
                 UserID            = 6,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.HolidayRequests.Add(new HolidayRequest()
             {
                 StartDate         = new DateTime(2020, 10, 12),
                 EndDate           = new DateTime(2020, 10, 21),
                 NumberOfDays      = GeneralUtils.CalculateWorkingDays(new DateTime(2020, 10, 12), new DateTime(2020, 10, 21)),
                 RequestStatusID   = 1,
                 UserID            = 9,
                 ConstraintsBroken = new ConstraintsBroken()
             });
             _entity.SaveChanges();
         }
     }
 }