Ejemplo n.º 1
0
        public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            Newtonsoft.Json.Linq.JObject getPersonsResponseAsJson = Newtonsoft.Json.Linq.JObject.Load(reader);

            GetPersonsResponse getPersonsResponse = new GetPersonsResponse();

            foreach (KeyValuePair <string, Newtonsoft.Json.Linq.JToken> organizationPersons in getPersonsResponseAsJson)
            {
                string organizationUnitNumber       = organizationPersons.Key;
                Newtonsoft.Json.Linq.JArray persons = organizationPersons.Value as Newtonsoft.Json.Linq.JArray;


                OrganizationPersons tmpOrganizationPersons = new OrganizationPersons();
                tmpOrganizationPersons.OrganizationUnitNumber = organizationUnitNumber;

                foreach (Newtonsoft.Json.Linq.JToken person in persons)
                {
                    HRworksConnector.Models.GeneralActions.PersonBaseData personBaseData = person.ToObject <HRworksConnector.Models.GeneralActions.PersonBaseData>();
                    tmpOrganizationPersons.Persons.Add(personBaseData);
                }

                getPersonsResponse.OrganizationsPersons.Add(tmpOrganizationPersons);
            }

            return(getPersonsResponse);
        }
Ejemplo n.º 2
0
        private static async System.Threading.Tasks.Task CallActions()
        {
            try
            {
                HRworksConnector.HRworksApi hrworksApi = new HRworksConnector.HRworksApi(AccessKey, SecretAccessKey, RealmIdentifier);

                #region GetAllPermanentEstablishments

                HRworksConnector.Models.GeneralActions.PermanentEstablishmentsResponse permanentEstablishmentsResponse = await hrworksApi.GeneralActions.GetAllPermanentEstablishmentsAsync();

                #endregion

                #region Target GetHolidays

                HRworksConnector.Models.GeneralActions.HolidaysResponse holidaysResponse = await hrworksApi.GeneralActions.GetHolidaysAsync(System.DateTime.Now.Year);

                #endregion

                #region Target GetAllAbsenceTypes

                HRworksConnector.Models.AbsenceActions.GetAllAbsenceTypesResponse getAllAbsenceTypesResponse = await hrworksApi.AbsenceActions.GetAllAbsenceTypesAsync();

                #endregion

                #region Target GetPersons

                HRworksConnector.Models.GeneralActions.GetPersonsResponse persons = await hrworksApi.GeneralActions.GetPersonsAsync();

                #endregion

                #region GetAvailableWorkingHours

                System.DateTime today = System.DateTime.Now.Date;

                System.DateTime dateFrom = today.Date.AddDays(-60);
                System.DateTime dateTo   = today.AddDays(60);

                HRworksConnector.Models.GeneralActions.GetAvailableWorkingHoursRequest getAvailableWorkingHoursRequest = new HRworksConnector.Models.GeneralActions.GetAvailableWorkingHoursRequest();
                getAvailableWorkingHoursRequest.BeginDate = dateFrom;
                getAvailableWorkingHoursRequest.EndDate   = dateTo;

                int counter = 0;

                HRworksConnector.Models.GeneralActions.PersonBaseData[] personsAsArray = persons.ToPersonArray();

                foreach (HRworksConnector.Models.GeneralActions.PersonBaseData personBaseData in personsAsArray)
                {
                    counter++;
                    getAvailableWorkingHoursRequest.PersonnelNumbers.Add(personBaseData.PersonnelNumber);

                    if (counter > 30)
                    {
                        break;
                    }
                }

                HRworksConnector.Models.GeneralActions.GetAvailableWorkingHoursResponse getAvailableWorkingHoursResponse = await hrworksApi.GeneralActions.GetAvailableWorkingHoursAsync(getAvailableWorkingHoursRequest);

                #endregion

                #region Target GetAbsences

                string[] activeKrankAndUrlaubKeys = getAllAbsenceTypesResponse.GetActiveKrankAndUrlaubKeys();

                // Krank- und Urlaubsmeldungen holen
                foreach (HRworksConnector.Models.GeneralActions.PersonBaseData personBaseData in persons.ToPersonArray())
                {
                    HRworksConnector.Models.AbsenceActions.GetAbsencesRequest getAbsencesRequest = new HRworksConnector.Models.AbsenceActions.GetAbsencesRequest();
                    getAbsencesRequest.BeginDate = dateFrom;
                    getAbsencesRequest.EndDate   = dateTo;
                    getAbsencesRequest.PersonnelNumbers.Add(personBaseData.PersonnelNumber);
                    foreach (string activeKrankAndUrlaubKey in activeKrankAndUrlaubKeys)
                    {
                        getAbsencesRequest.Types.Add(activeKrankAndUrlaubKey);
                    }

                    HRworksConnector.Models.AbsenceActions.GetAbsencesResponse getAbsencesResponse = await hrworksApi.AbsenceActions.GetAbsencesAsync(getAbsencesRequest);
                }

                #endregion

                #region Target GetPersonMasterData

                string personnelNumber = string.Empty;

                if (persons.OrganizationsPersons.Count > 0)
                {
                    System.Random random  = new System.Random();
                    int           randPos = random.Next(persons.OrganizationsPersons.Count - 1);
                    HRworksConnector.Models.GeneralActions.OrganizationPersons organizationPersons = persons.OrganizationsPersons[randPos];

                    randPos = random.Next(organizationPersons.Persons.Count - 1);

                    HRworksConnector.Models.GeneralActions.PersonBaseData tmPersonBaseData = organizationPersons.Persons[randPos];
                    personnelNumber = tmPersonBaseData.PersonnelNumber;
                }

                HRworksConnector.Models.EmployeeActions.GetPersonMasterDataRequest getPersonMasterDataRequest = new HRworksConnector.Models.EmployeeActions.GetPersonMasterDataRequest();
                getPersonMasterDataRequest.PersonnelNumbers.Add(personnelNumber);
                HRworksConnector.Models.EmployeeActions.GetPersonMasterDataResponse getPersonMasterDataResponse = await hrworksApi.EmployeeActions.GetPersonMasterDataAsync(getPersonMasterDataRequest);

                #endregion

                #region Target GetAllOrganizationUnits

                HRworksConnector.Models.GeneralActions.OrganizationUnitsResponse allOrganizationUnits = await hrworksApi.GeneralActions.GetAllOrganizationUnitsAsync();

                System.Console.WriteLine("-- GetAllOrganizationUnits-- ");
                foreach (HRworksConnector.Models.GeneralActions.OrganizationUnit organizationUnit in allOrganizationUnits.OrganizationUnits)
                {
                    System.Console.WriteLine(organizationUnit.ToString());
                }

                #endregion

                #region Target GetPresentPersonsOfOrganizationUnit

                if (allOrganizationUnits.OrganizationUnits.Count == 0)
                {
                    return;
                }

                string tmpOrganizationUnitNumber = allOrganizationUnits.OrganizationUnits[0].OrganizationUnitNumber;
                string tmpOrganizationUnitName   = allOrganizationUnits.OrganizationUnits[0].OrganizationUnitName;

                System.Console.WriteLine();
                System.Console.WriteLine();

                // Target GetPresentPersonsOfOrganizationUnit
                HRworksConnector.Models.GeneralActions.PersonsOfOrganizationUnitResponse personsOfOrganizationUnitResponse = await hrworksApi.GeneralActions.GetPresentPersonsOfOrganizationUnitAsync(tmpOrganizationUnitNumber);

                System.Console.WriteLine(string.Format("-- GetPresentPersonsOfOrganizationUnit von {0} ({1}) -- ", tmpOrganizationUnitName, tmpOrganizationUnitNumber));
                foreach (HRworksConnector.Models.GeneralActions.PersonBaseData personBaseData in personsOfOrganizationUnitResponse.Persons)
                {
                    System.Console.WriteLine(personBaseData.ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }