public List <APIPerson> GetPeople(int id)
        {
            // URL to call this is https://localhost:44390/API/GetPeople
            // Because the Controller is APIController (drops the controller bit in the URL)
            // GetPeople is the name of the fuction, once it created from APIModel

            List <APIPerson> PersonList = new List <APIPerson>();
            // List used in place of a database backend, just to playwith
            // Here is the list being created and data added.
            APIPerson Person = new APIPerson();

            Person.age    = 21;
            Person.gender = "Male";
            Person.id     = 1;
            Person.name   = "Tony";
            PersonList.Add(Person);
            APIPerson Person2 = new APIPerson();

            Person2.age    = 31;
            Person2.gender = "FeMale";
            Person2.id     = 2;
            Person2.name   = "Teresa";
            PersonList.Add(Person2);
            return(PersonList);
        }
Пример #2
0
        public APIPerson.Person GetPerson(object pid)
        {
            var api = new APIPerson(db);
            var p   = api.GetPersonData(pid.ToInt());

            return(p);
        }
Пример #3
0
        private void UpdateVacationBalances(APIPerson apiPerson, ref Person person)
        {
            var personId = person.Id;

            foreach (var apiEmployment in apiPerson.Employments)
            {
                var apiVacationBalance = apiEmployment.VacationBalance;
                if (apiVacationBalance != null)
                {
                    var employment = person.Employments.SingleOrDefault(e => e.EmploymentId.ToString() == apiEmployment.EmployeeNumber && (e.EndDateTimestamp == 0 || e.EndDateTimestamp >= GetUnixTime(DateTime.Now.Date)));
                    if (employment != null)
                    {
                        if (employment.VacationBalance == null)
                        {
                            employment.VacationBalance = new VacationBalance
                            {
                                PersonId     = person.Id,
                                EmploymentId = employment.Id,
                                Year         = apiVacationBalance.VacationEarnedYear + 1
                            };
                        }
                        employment.VacationBalance.Year = apiVacationBalance.VacationEarnedYear + 1;
                        employment.VacationBalance.FreeVacationHours = apiVacationBalance.FreeVacationHoursTotal ?? 0;
                        employment.VacationBalance.TransferredHours  = apiVacationBalance.TransferredVacationHours ?? 0;
                        employment.VacationBalance.VacationHours     = apiVacationBalance.VacationHoursWithPay ?? 0;
                        employment.VacationBalance.UpdatedAt         = GetUnixTime(apiVacationBalance.UpdatedDate);
                    }
                }
            }
        }
Пример #4
0
        public APIPerson.Person GetSpouse(object pid)
        {
            var p1 = db.LoadPersonById(pid.ToInt());

            if (p1 == null)
            {
                return(null);
            }
            var api = new APIPerson(db);
            var p   = api.GetPersonData(p1.SpouseId ?? 0);

            return(p);
        }
Пример #5
0
        private void mapAPIPerson(APIPerson apiPerson, ref Person personToInsert)
        {
            personToInsert.CprNumber = apiPerson.CPR;
            personToInsert.FirstName = apiPerson.FirstName ?? "ikke opgivet";
            personToInsert.LastName  = apiPerson.LastName ?? "ikke opgivet";
            personToInsert.Initials  = apiPerson.Initials ?? "";
            // only update email if supplied
            if (apiPerson.Email != null || personToInsert.Mail == null)
            {
                personToInsert.Mail = apiPerson.Email ?? "";
            }
            foreach (var existingEmployment in personToInsert.Employments.Where(e => e.EndDateTimestamp == 0 || e.EndDateTimestamp >= GetUnixTime(DateTime.Now.Date)))
            {
                // if database active employment does not exist in source then set end date
                if (!apiPerson.Employments.Select(s => s.EmployeeNumber).Contains(existingEmployment.EmploymentId.ToString()))
                {
                    existingEmployment.EndDateTimestamp = GetUnixTime(DateTime.Now.Date);
                }
            }
            personToInsert.IsActive = false;
            foreach (var sourceEmployment in apiPerson.Employments)
            {
                var employment = personToInsert.Employments.Where(d => d.EmploymentId.ToString() == sourceEmployment.EmployeeNumber && (d.EndDateTimestamp == 0 || d.EndDateTimestamp >= GetUnixTime(DateTime.Now.Date))).FirstOrDefault();

                if (employment == null)
                {
                    employment = new Employment();
                    personToInsert.Employments.Add(employment);
                }
                var orgUnitId = _orgUnitRepo.AsNoTracking().Where(o => o.OrgId.ToString() == sourceEmployment.OrgUnitId).Select(o => o.Id).First();
                employment.OrgUnitId          = orgUnitId;
                employment.Position           = sourceEmployment.Position ?? "Ingen stillingsbetegnelse";
                employment.IsLeader           = sourceEmployment.Manager;
                employment.StartDateTimestamp = GetUnixTime(sourceEmployment.FromDate ?? DateTime.Now.Date);
                employment.ExtraNumber        = sourceEmployment.ExtraNumber ?? 0;
                employment.EmploymentType     = sourceEmployment.EmploymentType ?? 0;
                employment.CostCenter         = sourceEmployment.CostCenter == null ? 0 : long.Parse(sourceEmployment.CostCenter);
                employment.EmploymentId       = sourceEmployment.EmployeeNumber;
                employment.EndDateTimestamp   = sourceEmployment.ToDate == null ? 0 : GetUnixTime(sourceEmployment.ToDate.Value.AddDays(1));
                employment.InstituteCode      = sourceEmployment.InstituteCode;
                // only set person active to true if person has a current or future employment
                if (sourceEmployment.ToDate == null || sourceEmployment.ToDate >= DateTime.Now.Date)
                {
                    personToInsert.IsActive = true;
                }
            }
        }
Пример #6
0
        public void UpdateHomeAddress(APIPerson apiPerson, ref Person person)
        {
            if (apiPerson.Address == null)
            {
                _logger.LogWarning($"No home address supplied for {apiPerson.FirstName} {apiPerson.LastName}");
                return;
            }
            var splitStreetAddress = SplitAddressOnNumber(apiPerson.Address.Street);
            var apiAddress         = new Address
            {
                Description  = person.FullName,
                StreetName   = splitStreetAddress.ElementAt(0),
                StreetNumber = splitStreetAddress.Count > 1 ? splitStreetAddress.ElementAt(1) : "1",
                ZipCode      = apiPerson.Address.PostalCode,
                Town         = apiPerson.Address.City ?? "",
            };

            apiAddress = _launderer.Launder(apiAddress);
            var apiPersonalAddress = new PersonalAddress()
            {
                PersonId     = person.Id,
                Type         = PersonalAddressType.Home,
                StreetName   = apiAddress.StreetName,
                StreetNumber = apiAddress.StreetNumber,
                ZipCode      = apiAddress.ZipCode,
                Town         = apiAddress.Town,
                Latitude     = apiAddress.Latitude ?? "",
                Longitude    = apiAddress.Longitude ?? "",
                Description  = apiAddress.Description
            };
            var homeAddress = person.PersonalAddresses.Where(a => a.Type == PersonalAddressType.Home).FirstOrDefault();

            if (homeAddress == null)
            {
                person.PersonalAddresses.Add(apiPersonalAddress);
            }
            else if (homeAddress != apiPersonalAddress)
            {
                homeAddress.Type = PersonalAddressType.OldHome;
                person.PersonalAddresses.Add(apiPersonalAddress);
            }
        }