Пример #1
0
        public FinderInputs ParseInputs(string input)
        {
            try
            {
                // Assume date is 3 parts
                var parts = input.Split(' ');

                if (parts.Length < 4)
                {
                    throw new ArgumentException("Not enough input parts");
                }

                var partnerParts = parts.Take(parts.Length - 3);
                var partnerName  = partnerParts.Join(" ");

                var dateParts = parts.TakeLast(3);
                var date      = dateParts.Join(" ");

                return(new FinderInputs
                {
                    PartnerName = partnerName,
                    Date = MappingHelpers.ParseDate(date)
                });
            }
            catch (Exception)
            {
                throw new ArgumentException("Input should be in the format 'partner name 1st Jun 2012'");
            }
        }
        //Calls the repositoryClient to get a list of meals by the user in the RecipeCalendar table for the next 6 days
        //groups these meals by MealTime (breakfast,lunch,dinner,snack)
        //Loops through the different gorupings in the meal group and maps out the meal to the correct day (mealNameOne, mealNameTwo)
        public async Task <ActionResult> MealCalendar()
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var meals  = await _repositoryClient.GetMealPlan(userId);

            var mealPlan   = new List <MealCalendarDataRowViewModel>();
            var mealGroups = meals.GroupBy(m => m.MealTime);

            foreach (var group in mealGroups.OrderBy(m => (MealTimeType)Enum.Parse(typeof(MealTimeType), m.Key)))
            {
                var mealType = new MealCalendarDataRowViewModel();
                mealType.MealTimeType = (MealTimeType)Enum.Parse(typeof(MealTimeType), group.Key);
                var mealsByDay = group.ToList();
                mealType.MealNameOne = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today), _recipeClient, _repositoryClient);

                mealType.MealNameTwo = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(1)), _recipeClient, _repositoryClient);

                mealType.MealNameThree = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(2)), _recipeClient, _repositoryClient);

                mealType.MealNameFour = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(3)), _recipeClient, _repositoryClient);

                mealType.MealNameFive = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(4)), _recipeClient, _repositoryClient);

                mealType.MealNameSix = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(5)), _recipeClient, _repositoryClient);

                mealType.MealNameSeven = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(6)), _recipeClient, _repositoryClient);

                mealPlan.Add(mealType);
            }
            return(View(mealPlan));
        }
Пример #3
0
        public static void GetSelectionPropertyWithNoSuitablePropertyThrows()
        {
            var ex = Record.Exception(() => MappingHelpers.GetSelectionProperty(typeof(ClassWithNoValidSelectionProperties)));

            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("Could not find public read/write non-generic value type property to use for a default query against ElasticLinq.Test.Mapping.MappingHelpersTests+ClassWithNoValidSelectionProperties.", ex.Message);
        }
Пример #4
0
        public static void GetSelectionPropertyReturnsRequiredProperty()
        {
            var expected = TypeHelper.GetMemberInfo((ClassWithRequiredAttributeProperty c) => c.IsRequired);

            var actual = MappingHelpers.GetTypeSelectionProperty(typeof(ClassWithRequiredAttributeProperty));

            Assert.Equal(expected, actual);
        }
Пример #5
0
        public static void GetSelectionPropertyReturnsReadWriteNonGenericValueProperty()
        {
            var expected = TypeHelper.GetMemberInfo((ClassWithOneValidSelectionProperty c) => c.Valid);

            var actual = MappingHelpers.GetTypeSelectionProperty(typeof(ClassWithOneValidSelectionProperty));

            Assert.Equal(expected, actual);
        }
Пример #6
0
 public PartnerContract Map(string[] parts)
 {
     return(new PartnerContract
     {
         Partner = parts[0],
         Usage = MappingHelpers.ParseUsages(parts[1])[0]
     });
 }
Пример #7
0
        public static VersionInfo?GetVersionOrAddNull(Converter item, uint version)
        {
            if (item._hasOneVersion)
            {
                return(version > 0 ? null : item._versionCache.OneVersion);
            }

            return(MappingHelpers.GetExistingOrAddNull(item._versionCache.MultipleVersions, version));
        }
Пример #8
0
        public static void GetSelectionPropertyReturnsReadWriteNonGenericValueProperty()
        {
            var selectionProperty = MappingHelpers.GetSelectionProperty(typeof(ClassWithOneValidSelectionProperty));

            Assert.IsAssignableFrom <PropertyInfo>(selectionProperty);
            Assert.Equal("Valid", selectionProperty.Name);
            Assert.Equal(typeof(ClassWithOneValidSelectionProperty), selectionProperty.DeclaringType);
            Assert.Equal(typeof(int), selectionProperty.PropertyType);
        }
Пример #9
0
        internal static SaveBaseMembersAttribute[]? GetBaseMembersAttributes(ref IntermediateMappingContext ctx, Type type)
        {
            SaveBaseMembersAttribute[] attr = (SaveBaseMembersAttribute[])type.GetCustomAttributes <SaveBaseMembersAttribute>(false);
            if (attr.Length == 0)
            {
                return(null);
            }

            MappingHelpers.ProcessVersionedAttributes(ref ctx.HighestVersion, attr);
            return(attr);
        }
Пример #10
0
 public MusicContract Map(string[] parts)
 {
     return(new MusicContract
     {
         Artist = parts[0],
         Title = parts[1],
         Usages = MappingHelpers.ParseUsages(parts[2]),
         StartDate = MappingHelpers.ParseDate(parts[3]),
         EndDate = string.IsNullOrEmpty(parts[4]) ? null : (DateTime?)MappingHelpers.ParseDate(parts[4])
     });
 }
Пример #11
0
        internal static SaveInheritanceAttribute[]? GetInheritanceAttributesByReflection(Type classType, ref uint highestVersion)
        {
            var inheritanceInfo = (SaveInheritanceAttribute[])classType.GetCustomAttributes <SaveInheritanceAttribute>(false);

            if (inheritanceInfo == null)
            {
                return(null);
            }

            MappingHelpers.ProcessVersionedAttributes(ref highestVersion, inheritanceInfo);
            return(inheritanceInfo);
        }
Пример #12
0
        private static TransferHelper <Models.BaseModel> GetHelperForBaseModel()
        {
            var helper = new WannaApp
                         Helpers.MappingHelpers.TransferHelper <Models.BaseModel>()
                         .SetDynamicColumnsFor("DynamicStrings", new List <string> {
                "frans", "demo", "Geert"
            })
                         .SetDynamicColumnsFor("DynamicInts", new List <string> {
                "Eerste", "Tweede"
            });

            return(helper);
        }
Пример #13
0
        static VersionInfo GetVersionInfo(Converter converter, uint version, MapGenerator gen)
        {
            (VersionInfo? newVer, bool usesHeader) = converter.GetVersionInfo(new InitializeInfo(converter.ItemType, gen), version);

            SaveInheritanceAttribute?inheritanceInfo = null;

            if (converter._allInheritanceAttributes != null)
            {
                inheritanceInfo = MappingHelpers.FindAttributeForVersion(converter._allInheritanceAttributes, version);
            }

            newVer ??= new VersionInfo(usesHeader);
            newVer.Assign(version, usesHeader, inheritanceInfo);

            return(newVer);
        }
Пример #14
0
        internal static void UpdateContextFromItem(ref IntermediateMappingContext ctx, IntermediateItem newItem)
        {
            // Check ordering
            if (ctx.TranslationCurrentOrderInfo != -1)
            {
                if (newItem.Order >= ctx.TranslationCurrentOrderInfo)
                {
                    ctx.TranslationCurrentOrderInfo = newItem.Order;
                }
                else
                {
                    ctx.TranslationCurrentOrderInfo = -1;
                }
            }

            MappingHelpers.UpdateHighestVersionFromRange(ref ctx.HighestVersion, newItem.StartVer, newItem.EndVer);
        }
Пример #15
0
        public static void GetSelectionPropertyWithNoSuitablePropertyReturnsNull()
        {
            var actual = MappingHelpers.GetTypeSelectionProperty(typeof(ClassWithNoValidSelectionProperties));

            Assert.Null(actual);
        }