示例#1
0
        public static CreateEmployeeVacationModel CreateEmployeeVacationRequest(int userId)
        {
            CreateEmployeeVacationModel model = new CreateEmployeeVacationModel();

            model.EmployeeVacation = new EmployeeVacation()
            {
                EmployeeUserId = userId,
                StartDate      = DateTimeHelper.Today(),
                EndDate        = DateTimeHelper.Today()
            };
            model.VacationTypesList = VacationTypesRepositories.GetVacationTypesExceptUnpaid();
            return(model);
        }
示例#2
0
        public static void CreateEmployeeVacationRequest(CreateEmployeeVacationModel model)
        {
            model.Succeeded = false;
            if (model.EmployeeVacation.StartDate.Date.CompareTo(DateTimeHelper.Today().Date) < 0 && !model.IsAdmin)
            {
                model.ErrorMessage = "Start Date Must Not be Less than Today";
                return;
            }
            if (model.EmployeeVacation.EndDate.Date.CompareTo(DateTimeHelper.Today().Date) < 0 && !model.IsAdmin)
            {
                model.ErrorMessage = "End Date Must be Greater than Today";
                return;
            }
            if (model.EmployeeVacation.EndDate.CompareTo(model.EmployeeVacation.StartDate) < 0)
            {
                model.ErrorMessage = "End Date Must be Later than Start Date";
                return;
            }
            if (model.EmployeeVacation.StartDate.Year != model.EmployeeVacation.EndDate.Year)
            {
                model.ErrorMessage = "End Date Must be in same Start Date Year.";
                return;
            }

            model.EmployeeVacation.StatusId     = model.IsAdmin ? (int)EVacationStatus.Approved : (int)EVacationStatus.Pending;
            model.VacationTypesList             = VacationTypesRepositories.GetVacationTypesExceptUnpaid();
            model.EmployeeVacation.VacationDays = GetRequestedVacationDays(model.EmployeeVacation.StartDate, model.EmployeeVacation.EndDate);
            if (model.EmployeeVacation.VacationDays < 1)
            {
                model.ErrorMessage = "Requested Vacation Period is already Vacation in our system ;).";
                return;
            }
            if (!IsRequestedVacationDaysValid(model))
            {
                model.ErrorMessage = "Requested Vacation Days Must be less than Remaining Days Of This Vacation.";
                return;
            }
            if (IsVacationDaysTakenBefore(model))
            {
                model.ErrorMessage = "There are days or part of them was requested before";
                return;
            }

            EmployeeVacationsRepositories.InsertNewEmployeeVacation(model.EmployeeVacation);
            //EmailHelper.VacationSendEmail(model, SessionData.UserName);
            model.Succeeded = true;
        }