public JsonResult GetProxiesByMe(int EServiceTypeID)
        {
            int    OrganizationID        = this.WindowsUserOrganizationID;
            string ManagerEmployeeCodeNo = this.WindowsUserIdentity;

            EServicesTypesEnum?        EServiceTypeEnum = EServiceTypeID == 0 ? null : (EServicesTypesEnum?)EServiceTypeID;
            List <EServicesProxiesBLL> EServiceProxyList
                = new EServicesProxiesBLL().GetByFromEmployeeCodeID(this.WindowsEmployeeCode.EmployeeCodeID, EServiceTypeEnum);

            return(Json(new
            {
                data = EServiceProxyList.Select(
                    item => new
                {
                    item.EServiceProxyID,
                    EServiceTypeName = item.EServiceType.EServiceTypeName,
                    ToEmployeeCodeID = item.ToEmployee.EmployeeCodeID,
                    ToEmployeeCodeNo = item.ToEmployee.EmployeeCodeNo,
                    ToEmployeeNameAr = item.ToEmployee.Employee.EmployeeNameAr,
                    item.StartDate,
                    item.EndDate,
                    item.IsActive,
                    EServiceProxyStatus = item.EServiceProxyStatus.EServiceProxyStatus,
                    item.Notes
                })
            }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllEmployeesManagersByOrganizationID(int EServiceTypeID)
        {
            int    OrganizationID        = this.WindowsUserOrganizationID;
            string ManagerEmployeeCodeNo = this.WindowsUserIdentity;

            EServicesProxiesBLL EServiceProxy
                = new EServicesProxiesBLL().GetActiveByFromEmployeeCodeID(this.WindowsEmployeeCode.EmployeeCodeID, (EServicesTypesEnum)EServiceTypeID);
            int ToEmployeeProxyAssigned               = EServiceProxy == null ? 0 : EServiceProxy.ToEmployee.EmployeeCodeID;
            List <EmployeesCodesBLL> Orgs             = new EmployeesCodesBLL().GetAllEmployeesManagersByOrganizationID(OrganizationID, (EServicesTypesEnum)EServiceTypeID);
            List <EServicesProxiesChartViewModel> lst = new List <EServicesProxiesChartViewModel>();
            EServicesProxiesChartViewModel        obj;

            foreach (var item in Orgs)
            {
                obj = MapToChartVM(item, ToEmployeeProxyAssigned);
                if (obj != null)
                {
                    lst.Add(obj);
                }
            }
            //lst.AddRange(Orgs.Select(x => MapToChartVM(x, ToEmployeeProxyAssigned)).ToList());

            if (Orgs != null)
            {
                return(Json(new
                {
                    total = Orgs.Count,
                    data = lst
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                throw new Exception();
            }
        }
        public JsonResult GetActiveEServiceProxy(int EServiceTypeID)
        {
            int    OrganizationID        = this.WindowsUserOrganizationID;
            string ManagerEmployeeCodeNo = this.WindowsUserIdentity;

            EServicesProxiesBLL EServiceProxy
                = new EServicesProxiesBLL().GetActiveByFromEmployeeCodeID(this.WindowsEmployeeCode.EmployeeCodeID, (EServicesTypesEnum)EServiceTypeID);

            EServicesProxiesViewModel VM = new EServicesProxiesViewModel();

            if (EServiceProxy != null)
            {
                VM.EServiceProxyID = EServiceProxy.EServiceProxyID;
                VM.StartDate       = EServiceProxy.StartDate;
                VM.EndDate         = EServiceProxy.EndDate;
                VM.ToEmployee      = new EmployeesViewModel()
                {
                    EmployeeCodeID = EServiceProxy.ToEmployee.EmployeeCodeID,
                    EmployeeCodeNo = EServiceProxy.ToEmployee.EmployeeCodeNo,
                    EmployeeNameAr = EServiceProxy.ToEmployee.Employee.EmployeeNameAr
                };
            }
            return(Json(new
            {
                data = VM
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateEServiceProxy(EServicesProxiesViewModel EServiceProxyVM)
        {
            int OrganizationID = this.WindowsUserOrganizationID;
            EServicesProxiesBLL EServiceProxy = new EServicesProxiesBLL();

            EServiceProxy.StartDate    = EServiceProxyVM.StartDate;
            EServiceProxy.FromEmployee = new EmployeesCodesBLL()
            {
                EmployeeCodeID = EServiceProxyVM.FromEmployee.EmployeeCodeID.Value
            };
            EServiceProxy.ToEmployee = new EmployeesCodesBLL()
            {
                EmployeeCodeID = EServiceProxyVM.ToEmployee.EmployeeCodeID.Value
            };
            EServiceProxy.Notes        = EServiceProxyVM.Notes;
            EServiceProxy.EServiceType = new EServicesTypesBLL()
            {
                EServiceTypeID = EServiceProxyVM.EServiceType.EServiceTypeID
            };
            EServiceProxy.LoginIdentity = this.WindowsEmployeeCode;
            Result result = EServiceProxy.Add();

            EServicesProxiesChartViewModel ChartVM =
                this.MapToChartVM(new EmployeesCodesBLL().GetAllEmployeesManagersByOrganizationID(OrganizationID,
                                                                                                  (EServicesTypesEnum)EServiceProxyVM.EServiceType.EServiceTypeID, EServiceProxyVM.ToEmployee.EmployeeCodeID.Value).FirstOrDefault(),
                                  EServiceProxyVM.ToEmployee.EmployeeCodeID.Value);

            if (result.EnumMember == EServicesProxiesEnum.Done.ToString())
            {
                // done
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseLoginManagerIsSameAsProxyEmployee.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationEServicesProxiesLoginManagerIsSameAsProxyEmployeeText);
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseThereIsAlreadyActiveProxyExist.ToString())
            {
                string msg = string.Format(Resources.Globalization.ValidationEServicesProxiesThereIsAlreadyActiveProxyExistsText,
                                           ((EServicesProxiesBLL)result.Entity).ToEmployee.Employee.EmployeeNameAr);
                throw new CustomException(msg);
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseStartDateRequried.ToString())
            {
                throw new CustomException(string.Format(Resources.Globalization.RequiredFieldText, Resources.Globalization.StartDateText));
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseThereIsPendingEVacationRequestExist.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationEServicesProxiesThereIsPendingEVacationRequestExistText);
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseThereIsVacationExist.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationEServicesProxiesThereIsVacationExistText);
            }

            return(Json(new { node = ChartVM }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RevokeEServiceProxy(int EServiceProxyID)
        {
            Result result = new EServicesProxiesBLL()
            {
                LoginIdentity = this.WindowsEmployeeCode
            }
            .RevokeEServiceProxy(EServiceProxyID, EServicesProxiesStatusEnum.Expired);

            if (result.EnumMember == EServicesProxiesEnum.Done.ToString())
            {
                // do nothing
            }
            else if (result.EnumMember == EServicesProxiesEnum.RejectedBecauseEServiceProxyIsNotActive.ToString())
            {
                throw new CustomException(Resources.Globalization.ValidationEServiceProxyIsNotActiveText);
            }

            return(Json(new { EServiceProxyID = EServiceProxyID }, JsonRequestBehavior.AllowGet));
        }