public static ReservationForm ReadFromWit(WitResult witResult)
        {
            var form = new ReservationForm();

            if (witResult.TryFindEntity("restaurantname", out var restaurantNameEntity))
            {
                form.RestaurantName = restaurantNameEntity.Value;
            }

            if (witResult.TryFindEntities("number", out var countEntities))
            {
                var countEntity = countEntities.Skip(1).FirstOrDefault();
                if (countEntity != null)
                {
                    form.PeopleCount = int.Parse(countEntity.Value);
                }
            }

            if (witResult.TryFindEntity(WitBuiltinEntities.DateTime, out var dateTimeEntity) && DateTimeParser.TryParse(dateTimeEntity, out var range))
            {
                form.ReservationDate = new DateTimeA(range.StartDate.DateTime);
            }

            return(form);
        }
예제 #2
0
        public static ReservationForm ReadFromWit(WitResult witResult)
        {
            var form = new ReservationForm();

            if (witResult.TryFindEntity("restaurantname", out var restaurantNameEntity))
            {
                form.RestaurantName = restaurantNameEntity.Value;
            }

            if (witResult.TryFindEntity("people_count", out var countEntity))
            {
                form.PeopleCount = int.Parse(countEntity.Value);
            }

            if (witResult.TryFindEntity(WitBuiltinEntities.DateTime, out var dateTimeEntity) && DateTimeParser.TryParse(dateTimeEntity, out var range))
            {
                form.ReservationDate = range.StartDate.DateTime;
            }

            return(form);
        }
 private static bool HasNotFoundDate(ReservationForm form) => form.ReservationDate == null;
 private static bool HasNotClientQuantity(ReservationForm form) => form.PeopleCount == 0;
 private static bool HasNotRestaurantName(ReservationForm form) => string.IsNullOrEmpty(form.RestaurantName);