예제 #1
0
        public void UpdateClothesCategories(Coste_Florina_ProiectContext context,
                                            string[] selectedCategories, Clothes clothesToUpdate)
        {
            if (selectedCategories == null)
            {
                clothesToUpdate.ClothesCategories = new List <ClothesCategory>();
                return;
            }
            var selectedCategoriesHS = new HashSet <string>(selectedCategories);
            var clothesCategories    = new HashSet <int>
                                           (clothesToUpdate.ClothesCategories.Select(c => c.Category.ID));

            foreach (var cat in context.Category)
            {
                if (selectedCategoriesHS.Contains(cat.ID.ToString()))
                {
                    if (!clothesCategories.Contains(cat.ID))
                    {
                        clothesToUpdate.ClothesCategories.Add(
                            new ClothesCategory
                        {
                            ClothesID  = clothesToUpdate.ID,
                            CategoryID = cat.ID
                        });
                    }
                }
                else
                {
                    if (clothesCategories.Contains(cat.ID))
                    {
                        ClothesCategory courseToRemove
                            = clothesToUpdate
                              .ClothesCategories
                              .SingleOrDefault(i => i.CategoryID == cat.ID);
                        context.Remove(courseToRemove);
                    }
                }
            }
        }
예제 #2
0
        public void PopulateAssignedCategoryData(Coste_Florina_ProiectContext context, Clothes clothes)
        {
            var allCategories     = context.Category;
            var clothesCategories = new HashSet <int>(
                clothes.ClothesCategories.Select(c => c.ClothesID));

            AssignedCategoryDataList = new List <AssignedCategoryData>();
            foreach (var cat in allCategories)
            {
                AssignedCategoryDataList.Add(new AssignedCategoryData
                {
                    CategoryID = cat.ID,
                    Name       = cat.CategoryName,
                    Assigned   = clothesCategories.Contains(cat.ID)
                });
            }
        }