Пример #1
0
        public Result MakeDecisionOfEVacationRequest(EVacationsRequestsBLL EVacationRequestObj, EVacationRequestStatusEnum EVacationRequestStatus)
        {
            try
            {
                Result result = null;
                EVacationRequestObj.ApprovedBy = new EmployeesCodesBLL().GetByEmployeeCodeNo(EVacationRequestObj.ApprovedBy.EmployeeCodeNo);
                EVacationsRequestsBLL EVacationsRequestsData = new EVacationsRequestsBLL().GetEVacationsRequestsByEVacationRequestID(EVacationRequestObj.EVacationRequestID);

                #region Validate there is a decision of this e vacation request or not
                if (EVacationsRequestsData.EVacationRequestStatus.EVacationRequestStatusID != (int)EVacationRequestStatusEnum.Pending)
                {
                    result            = new Result();
                    result.Entity     = EVacationsRequestsData;
                    result.EnumMember = VacationsValidationEnum.RejectedBecauseOfEVacationRequestStatusNotPending.ToString();
                    return(result);
                }
                #endregion

                #region Validate the approver person is authorized to employee manager or not
                EmployeesCodesBLL ActualAuthorizedPerson = new EServicesAuthorizationsBLL().GetOrganizationAuthorizedPerson(EVacationsRequestsData.ActualEmployeeOrganization.OrganizationID, EServicesTypesEnum.Vacation).AuthorizedPerson;
                if (ActualAuthorizedPerson.EmployeeCodeNo != EVacationRequestObj.ApprovedBy.EmployeeCodeNo)
                {
                    result            = new Result();
                    result.EnumMember = VacationsValidationEnum.RejectedBeacuseOfApproverIsNotAuthorizedPerson.ToString();
                    result.Entity     = ActualAuthorizedPerson;
                    return(result);
                }
                #endregion

                string SMSMessage = string.Empty;
                // in case of approval, send the vacation data to vacations module to be added, after that change the status in e vacation requests module
                if (EVacationRequestStatus == EVacationRequestStatusEnum.Approved)
                {
                    #region Send vacation to vacations module
                    BaseVacationsBLL Vacation = new BaseVacationsBLL()
                    {
                        IsApprovedFromManager = true,
                        EVacationsRequest     = EVacationsRequestsData,
                        EmployeeCareerHistory = EVacationsRequestsData.EmployeeCareerHistory,
                        VacationType          = VacationsTypesEnum.Normal,
                        VacationStartDate     = EVacationsRequestsData.VacationStartDate,
                        VacationEndDate       = EVacationsRequestsData.VacationEndDate,
                        Notes         = EVacationsRequestsData.CreatorNotes,
                        ApprovedBy    = EVacationRequestObj.ApprovedBy,
                        LoginIdentity = EVacationsRequestsData.CreatedBy,
                        CreatedDate   = DateTime.Now,
                        IsCanceled    = false,
                    };
                    result = Vacation.Add();
                    #endregion

                    #region Update IsApproved in vacations module
                    result = Vacation.Approve();
                    #endregion

                    if (result.EnumMember == VacationsValidationEnum.Done.ToString())
                    {
                        result = ApproveEVacationRequest(EVacationRequestObj, EVacationRequestStatus);
                    }

                    SMSMessage = string.Format(Globalization.SMSEVacationRequestApprovedText, EVacationsRequestsData.VacationType.VacationTypeName, EVacationsRequestsData.VacationStartDate, EVacationsRequestsData.VacationPeriod);
                }
                else  // in case of refuse, change the status in e vacation requests module only
                {
                    result     = ApproveEVacationRequest(EVacationRequestObj, EVacationRequestStatus);
                    SMSMessage = Globalization.SMSEVacationRequestRefusedText;
                }

                #region Sending sms to employee to notify him the authorized person decision
                SMSBLL sMSBLL = new SMSBLL();
                sMSBLL.SendSMS(new SMSLogsBLL()
                {
                    BusinssSubCategory = BusinessSubCategoriesEnum.AuthorizedPersonDecisionForEVacationRequest,
                    DetailID           = EVacationsRequestsData.EVacationRequestID,
                    MobileNo           = EVacationsRequestsData.EmployeeCareerHistory?.EmployeeCode?.Employee?.EmployeeMobileNo,
                    Message            = SMSMessage,
                    CreatedBy          = EVacationRequestObj.ApprovedBy,
                });
                #endregion

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public ActionResult Create(VacationsViewModel VacationVM)
        {
            BaseVacationsBLL Vacation = null;

            if (!VacationVM.VacationStartDate.HasValue || !VacationVM.VacationEndDate.HasValue)
            {
                throw new CustomException(Resources.Globalization.RequiredStartDateAndEndDateText);
            }

            if (VacationVM.VacationType.VacationTypeID == (int)VacationsTypesEnum.Normal)
            {
                Vacation = GenericFactoryPattern <BaseVacationsBLL, NormalVacationsBLL> .CreateInstance();

                if (VacationVM.NormalVacationTypeID.HasValue)
                {
                    ((NormalVacationsBLL)Vacation).NormalVacationType = new NormalVacationsTypesBLL()
                    {
                        NormalVacationTypeID = VacationVM.NormalVacationTypeID.Value
                    }
                }
                ;
            }

            Vacation.EmployeeCareerHistory = new EmployeesCareersHistoryBLL().GetEmployeeCurrentJob(VacationVM.EmployeeCodeID.Value);
            Vacation.VacationType          = (VacationsTypesEnum)VacationVM.VacationType.VacationTypeID;
            Vacation.VacationStartDate     = VacationVM.VacationStartDate.Value.Date;
            Vacation.VacationEndDate       = VacationVM.VacationEndDate.Value.Date;
            Vacation.Notes = VacationVM.Notes;
            Vacation.IsApprovedFromManager = false;
            Vacation.LoginIdentity         = new EmployeesCodesBLL()
            {
                EmployeeCodeNo = this.WindowsUserIdentity,
                EmployeeCodeID = VacationVM.EmployeeCodeID.Value
            };

            Result result = Vacation.Add();

            if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfBeforeHiringDate.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.ValidationVacationBeforeHiringText, ((EmployeesCareersHistoryBLL)result.Entity).JoinDate.ToString(Classes.Helpers.CommonHelper.DateFormat)));
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBeacuseOfEmployeeNotHasActualOrganization.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationEmployeeNotHasActualOrganizationText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfDuringProbation.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.ValidationVacationDuringProbationText, ((EmployeesCareersHistoryBLL)result.Entity).ProbationEndDate.ToString(Classes.Helpers.CommonHelper.DateFormat)));
            }

            else if (result.EnumMember == VacationsValidationEnum.SportsSeasonDoesNotExist.ToString())
            {
                throw new CustomException(Resources.Globalization.SportsSeasonDoesNotExistText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfInvalidDates.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationInvalidDateText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfInvalidSportsDates.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationInvalidSportsDateText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfNoBalance.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationAlreadyReachTheVacationLimitText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfInvalidStartDate.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationInvalidVacationStartDateText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfConsumedMaxLimit.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationAlreadyReachTheNormalVacationLimitText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfNormalVacationBalanceExists.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfNormalVacationBalanceExistsText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfNormalVacationReachedToMaxLimitOfSeparatedDays.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfNormalVacationReachedToMaxLimitOfSeparatedDaysText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfVacationNotAllowedBetween1437and1438.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfVacationNotAllowedBetween1437and1438Text);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfVacationOutOfRange.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfVacationOutOfRangeText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseSickExceptionalVacationDatesOutOfRange.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfSickExceptionalVacationDatesOutOfRangeText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfErrorInTimeAttendanceApp.ToString())
            {
                throw new CustomException(Resources.Globalization.ErrorInTimeAttendanceAppText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfMarriageVacationAcceptedOneTime.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfMarriageVacationAcceptedOneTimeText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfNoActiveProxyCreatedToOtherPerson.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationBecauseOfNoActiveProxyCreatedToOtherPersonText);
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfEmployeeHasProxyByOtherPerson.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.ValidationBecauseOfThereIsProxyByOtherPersonText, ((EServicesProxiesBLL)result.Entity).FromEmployee?.Employee?.EmployeeNameAr,
                                                        ((EServicesProxiesBLL)result.Entity).StartDate.Date.ToString(Classes.Helpers.CommonHelper.DateFormat)));
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBeacuseOfNotAllowedWeekEndBetweenTwoVacations.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.ValidationNotAllowedWeekEndBetweenTwoVacationsText, ((BaseVacationsBLL)result.Entity).VacationStartDate.Date.ToString(Classes.Helpers.CommonHelper.DateFormat),
                                                        ((BaseVacationsBLL)result.Entity).VacationPeriod,
                                                        ((BaseVacationsBLL)result.Entity).VacationEndDate.Date.ToString(Classes.Helpers.CommonHelper.DateFormat),
                                                        ((BaseVacationsBLL)result.Entity).VacationTypeName));
            }

            else if (result.EnumMember == VacationsValidationEnum.RejectedBecauseOfEVacationRequestPendingExist.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.ValidationBecauseOfEVacationRequestPendingExistText, ((BaseVacationsBLL)result.Entity).EVacationsRequest.EVacationRequestNo));
            }

            Classes.Helpers.CommonHelper.ConflictValidationMessage(result);

            Session["EVacationRequestNo"] = Vacation.EVacationsRequest.EVacationRequestNo;
            return(Json(new { EVacationRequestNo = Vacation.EVacationsRequest.EVacationRequestNo }, JsonRequestBehavior.AllowGet));
        }