示例#1
0
        public List <Employee> GetBirthdays()
        {
            //get allEmployeed list from ACME API
            List <Employee> getAllEmployee = Employees.GetEmployees();

            //get Exclusion list from ACME API
            List <int?> getExlusionList = BirthdayWishExclusion.GetExcluion();
            int         count           = 0;

            foreach (Employee data in getAllEmployee)
            {
                if (count > 100)
                {
                    data.DateOfBirth       = DateTime.Now;
                    data.EmploymentEndDate = DateTime.Now.AddDays(5);
                }
                count++;
            }

            // applied all considered conditions
            // Employee endDate should not be greater than today
            // Employee Startdate shoule not be less than today
            // Employee Birthday should be Today
            // And Employee should not be in Exclusion list
            //And Employee birth year should not be a leap year. (Assuming that's what in the task description) if that
            // is not the intention last condition can be removed && (!DateTime.IsLeapYear (a.DateOfBirth.Value.Year)))
            var _result = (from a in getAllEmployee
                           where (a.EmploymentStartDate <= DateTime.Now &&
                                  a.EmploymentEndDate >= DateTime.Now &&
                                  !getExlusionList.Contains(a.Id) &&
                                  (Convert.ToDateTime(a.DateOfBirth).ToShortDateString()) == DateTime.Now.ToShortDateString() &&
                                  (!DateTime.IsLeapYear(a.DateOfBirth.Value.Year)))
                           select a).ToList();


            return(_result);
        }
示例#2
0
        public static List <int?> GetExcluion()
        {
            const string       EXCLUSION_APIURL  = "/api/BirthdayWishExclusions";
            List <int?>        _result           = null;
            ConnectionProperty objConn           = new ConnectionProperty();
            CancellationToken  cancellationToken = default(CancellationToken);

            //initialize objects
            objConn.Initialize();


            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, BirthdayWishExclusion.GetExcluion(), "ApiBirthdayWishExclusionsGet", tracingParameters);
            }

            // Construct URL
            var _baseUrl = objConn.BaseUri.AbsoluteUri;
            var _url     = ExtensionMethods.BuildURL(_baseUrl, EXCLUSION_APIURL.ToString());

            using (var _httpClient = new HttpClient())
            {
                _httpClient.BaseAddress = new Uri(_url);
                _httpClient.DefaultRequestHeaders.Clear();
                _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var _httpResponse = _httpClient.GetAsync(EXCLUSION_APIURL).Result;

                HttpStatusCode _statusCode = _httpResponse.StatusCode;
                if ((int)_statusCode != 200)
                {
                    var ex = new HttpOperationException(string.Format("BirthdayWishExclusions Operation returned an invalid status code '{0}'", _statusCode));
                    throw ex;
                }
                if (_httpResponse.IsSuccessStatusCode)
                {
                    var _responseContent = _httpResponse.Content;

                    try
                    {
                        _result = JsonConvert.DeserializeObject <List <int?> >(_responseContent.ReadAsStringAsync().Result);
                    }
                    catch (Exception ex)
                    {
                        if (_httpResponse != null)
                        {
                            _httpResponse.Dispose();
                        }
                        throw new SerializationException("Unable to deserialize the response.", _responseContent.ToString(), ex);
                    }
                }
                if (_shouldTrace)
                {
                    ServiceClientTracing.Exit(_invocationId, _result);
                }

                return(_result);
            }
        }