Spontaneous.DataModel.MenuPart.CopyPartialMenuPart C# (CSharp) Method

CopyPartialMenuPart() public method

Function copy partial MenuPart (dishes which Ids in CopyList)
public CopyPartialMenuPart ( CopyList copyList, MenuPart copyFrom ) : void
copyList CopyList
copyFrom MenuPart
return void
        public void CopyPartialMenuPart(CopyList copyList, MenuPart copyFrom)
        {
            int tempDishId;
            //count of dishes to copy
            int copyCount = copyList.MenuPartsCopyList[0].DishesIdsList.Count;
            for (int i = 0; i < copyCount; i++)
            {
                tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i];
                Dish tempDish = new Dish();
                tempDish.CopyFrom(copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId));
                tempDish.Id = this.MaxDishId() + 1;
                tempDish.OrderBy = tempDish.Id;
                this.Dishes.Add(tempDish);
            }
        }

Usage Example

        public void TestCopyPartialDishesListToNewMenuPart_shouldCopyOnlySpecificDishesToOtherMenuPart_andSaveAllProptertiesIncludeDishId()
        {
            //arrange
            MenuPart copyFrom = new MenuPart()
            {
                Id = 13,
                OrderBy = 2,
                Name = "מנות עיקריות"
            };
            MenuPart copyTo = new MenuPart();

            Dish dish1 = new Dish()
            {
                Id = 1,
                Description = "סלט ירקות עם חתיכות חזה עוף",
                DishState = DishStateEnum.Active,
                Name = "סלט קיסר",
                NutritionFacts = new NutritionFacts(),
                ItemLocation = new Location() { Latitude = 30, Longitude = 27 },
                ImageUrl = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRqKcIkvCQDkCNQkXq0TWtiqRSF5ryYK7NYB79ZBVebpjKBVPcA",
                IsItPublic = true,
                MappedState = new SuspiciousState() { Index = 7.77 },
                RecipeId = 10,
                State = new SuspiciousState() { Index = 7.77 },
                OverrideIngredients = new List<Ingredient>()
            };
            Dish dish2 = new Dish()
            {
                Id = 3,
                Description = "שניצל מוגש עם צ'יפס",
                DishState = DishStateEnum.Active,
                Name = "שניצל",
                NutritionFacts = new NutritionFacts(),
                ItemLocation = new Location() { Latitude = 31, Longitude = 29 },
                ImageUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQX5WBzP336hF8Q0FQpk5TdX8m7GI7ymVqJMtyrzSA3afEkqfU8CA",
                IsItPublic = true,
                MappedState = new SuspiciousState() { Index = 8.88 },
                RecipeId = 28,
                State = new SuspiciousState() { Index = 8.88 },
                OverrideIngredients = new List<Ingredient>()
            };
            Dish dish3 = new Dish()
            {
                Id = 15,
                Description = "המבורגר 220גר עם צ'יפס בצד",
                DishState = DishStateEnum.Active,
                Name = "המבורגר",
                NutritionFacts = new NutritionFacts(),
                ItemLocation = new Location() { Latitude = 32, Longitude = 30 },
                ImageUrl = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTmEsDLKjW9dj_Vl8SMdESJkTBGncjY5QDt0sqK77txEUwSi2RzUA",
                IsItPublic = true,
                MappedState = new SuspiciousState() { Index = 50 },
                RecipeId = 169,
                State = new SuspiciousState() { Index = 50 },
                OverrideIngredients = new List<Ingredient>()
            };
            copyFrom.Dishes.Add(dish1);
            copyFrom.Dishes.Add(dish2);
            copyFrom.Dishes.Add(dish3);
            CopyList copyList = new CopyList()
            {
                CopyFromId = "11111",
                MenuPartsCopyList = new List<MenuPartCopy>()
            };
            //CopyFromList menuCopyFrom = new CopyFromList()
            //{
            //    RestaurantId = "11111",
            //    CopyMenuPartList = new List<MenuPartCopy>()
            //};
            copyList.MenuPartsCopyList.Add(new MenuPartCopy() { MenuPartId = 1, DishesIdsList = new List<int> { 1, 15 }, PartialCopy = true });
            //CopyList copyList = new CopyList() { CopyFrom = menuCopyFrom };

            //Create copy from data

            //act

            copyTo.CopyPartialMenuPart(copyList, copyFrom);

            //assert

            int tempDishId;
            for(int i=0; i < 2 ; i++)
            {
                tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i];
                string tempDishName = copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Name;
                int newDishId = copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName).Id;

                Assert.IsNull(copyTo.Dishes.FirstOrDefault(c => c.Id == 3));
                Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName));
                Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).Description, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Description);
                Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).RecipeId, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).RecipeId);
                Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).State, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).State);
                //check all other properties

            }
        }
All Usage Examples Of Spontaneous.DataModel.MenuPart::CopyPartialMenuPart