コード例 #1
0
        /// <summary>
        /// Get Availability Time from date
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public List <string> GetAvailabilityTime(string date)
        {
            //check input
            if (!DateTime.TryParseExact(date, "dd.MM.yyyy", CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.None, out var dt) &&
                !DateTime.TryParse(date, out dt))
            {
                return(new List <string>());
            }

            //get from cache
            var at = Caching.GetAvailabilityTime(dt);

            if (at != null)
            {
                return(at);
            }

            //get time list from DB
            var queryResult = _tp.GetAvailabilityTime(dt).GetAwaiter().GetResult();

            if (queryResult == null)
            {
                return(new List <string>());
            }

            //get Precedence first
            var min    = queryResult.Min(x => x.Precedence);
            var list   = queryResult.Where(x => x.Precedence == min).ToList();
            var result = ProcessAvailabilityTime(list, dt);

            //add to cache
            Caching.SetAvailabilityTime(date, result);

            return(result);
        }