示例#1
0
 private static ApiDemoResult determineName(ApiDemoPerson ApiDemo, ApiDemoResult result)
 {
     if (!string.IsNullOrWhiteSpace(ApiDemo.LastName) &&
         !string.IsNullOrWhiteSpace(ApiDemo.FirstName) &&
         !string.IsNullOrWhiteSpace(ApiDemo.MiddleName))
     {
         result          = result ?? new ApiDemoResult();
         result.FullName = string.Format(nameFormatLNCommaFNMN, ApiDemo.LastName, ApiDemo.FirstName, ApiDemo.MiddleName.Substring(0, 1));
     }
     else if (!string.IsNullOrWhiteSpace(ApiDemo.LastName) &&
              !string.IsNullOrWhiteSpace(ApiDemo.FirstName))
     {
         result          = result ?? new ApiDemoResult();
         result.FullName = string.Format(nameFormatLNCommaFN, ApiDemo.LastName, ApiDemo.FirstName);
     }
     else if (!string.IsNullOrWhiteSpace(ApiDemo.LastName))
     {
         result          = result ?? new ApiDemoResult();
         result.FullName = string.Format(nameFormatSingle, ApiDemo.LastName);
     }
     else if (!string.IsNullOrWhiteSpace(ApiDemo.FirstName))
     {
         result          = result ?? new ApiDemoResult();
         result.FullName = string.Format(nameFormatSingle, ApiDemo.FirstName);
     }
     return(result);
 }
示例#2
0
        public ApiDemoResult Get([FromUri] ApiDemoPerson ApiDemo)
        {
            ApiDemoResult result = null;

            if (ApiDemo != null)
            {
                result = determineName(ApiDemo, result);

                result = calculateAge(ApiDemo, result);

                result = processAddresses(ApiDemo, result);
            }

            return(result);
        }
示例#3
0
        private static ApiDemoResult calculateAge(ApiDemoPerson ApiDemo, ApiDemoResult result)
        {
            if (ApiDemo.DateOfBirth.HasValue && ApiDemo.DateOfBirth.Value < DateTime.Now)
            {
                var today = DateTime.Now;
                result = result ?? new ApiDemoResult();
                var age          = today.Subtract(ApiDemo.DateOfBirth.Value);
                var nextBirthday = new DateTime(today.Year, ApiDemo.DateOfBirth.Value.Month, ApiDemo.DateOfBirth.Value.Day);
                if (nextBirthday < today)
                {
                    nextBirthday = nextBirthday.AddYears(1);
                }
                var nextBirthdayDays = nextBirthday.Subtract(today);
                result.Age = string.Format(ageFormat, Math.Round(age.TotalDays / 365.25), Math.Round(age.TotalDays % 365.25) / 30.0, nextBirthdayDays.TotalDays);
            }

            return(result);
        }
示例#4
0
 private static ApiDemoResult processAddresses(ApiDemoPerson ApiDemo, ApiDemoResult result)
 {
     if (ApiDemo.Addresses != null && ApiDemo.Addresses.Count > 0)
     {
         foreach (var address in ApiDemo.Addresses)
         {
             if (!string.IsNullOrWhiteSpace(address.Address1) ||
                 !string.IsNullOrWhiteSpace(address.Address2) ||
                 !string.IsNullOrWhiteSpace(address.City) ||
                 !string.IsNullOrWhiteSpace(address.State) ||
                 !string.IsNullOrWhiteSpace(address.Zip5))
             {
                 result = result ?? new ApiDemoResult();
                 if (result.Addresses == null)
                 {
                     result.Addresses = new List <string>();
                 }
                 result.Addresses.Add(string.Format(addressFormat, address.Address1, address.Address2, address.City, address.State, address.Zip5, address.Zip4));
             }
         }
     }
     return(result);
 }