Exemple #1
0
        public IngredientFormViewModel(GroceriesContext context)
        {
            UnitRepository unitRepo = new UnitRepository(context);

            UnitsSelectList = new SelectList(unitRepo.GetUnits(), "Id", "PluralDescriptor");

            SectionRepository sectionRepo = new SectionRepository(context);

            SectionsSelectList = new SelectList(sectionRepo.GetSections(), "Id", "Name");
        }
Exemple #2
0
        public IngredientFormViewModel(GroceriesContext context, Ingredient ingredient)
        {
            Id        = ingredient.Id;
            Name      = ingredient.Name;
            UnitId    = ingredient.UnitId;
            Unit      = ingredient.Unit;
            SectionId = ingredient.SectionId;
            Section   = ingredient.Section;

            UnitRepository unitQueries = new UnitRepository(context);

            UnitsSelectList = new SelectList(unitQueries.GetUnits(), "Id", "PluralDescriptor", UnitId);

            SectionRepository sectionQueries = new SectionRepository(context);

            SectionsSelectList = new SelectList(sectionQueries.GetSections(), "Id", "Name", SectionId);
        }
Exemple #3
0
 public List <Section> GetSections(OrganizationalLevel level, int?superiorSectionId)
 {
     return(_sectionRepository.GetSections(level, superiorSectionId));
 }
Exemple #4
0
        public ProductListViewModel GetProductViewModel()
        {
            ProductListViewModel productViewModel = new ProductListViewModel();

            productViewModel.Products      = new List <Product>();
            productViewModel.Sections      = new List <Section>();
            productViewModel.Categories    = new List <Category>();
            productViewModel.Subcategories = new List <Subcategory>();
            ProductRepository     productRepository              = new ProductRepository();
            SectionRepository     sectionRepository              = new SectionRepository();
            CategoryRepositry     categoryRepository             = new CategoryRepositry();
            SubcategoryRepository subcategoryRepository          = new SubcategoryRepository();
            List <WebStoreData.Models.Product>     products      = productRepository.GetProducts().ToList();
            List <WebStoreData.Models.Section>     sections      = sectionRepository.GetSections().ToList();
            List <WebStoreData.Models.Category>    categories    = categoryRepository.GetCategories().ToList();
            List <WebStoreData.Models.Subcategory> subcategories = subcategoryRepository.GetSubcategories().ToList();
            var productMapper            = ObjectMapperManager.DefaultInstance.GetMapper <WebStoreData.Models.Product, WebStore.Model.Product>();
            var productDescriptionMapper = ObjectMapperManager.DefaultInstance.GetMapper <WebStoreData.Models.ProductDescription, WebStore.Model.ProductDescription>();

            var sectionMapper     = ObjectMapperManager.DefaultInstance.GetMapper <WebStoreData.Models.Section, WebStore.Model.Section>(new DefaultMapConfig().IgnoreMembers <WebStoreData.Models.Section, WebStore.Model.Section>(new [] { "Categories" }));
            var categoryMapper    = ObjectMapperManager.DefaultInstance.GetMapper <WebStoreData.Models.Category, WebStore.Model.Category>(new DefaultMapConfig().IgnoreMembers <WebStoreData.Models.Category, WebStore.Model.Category>(new [] { "Subcategories" }));
            var subcategoryMapper = ObjectMapperManager.DefaultInstance.GetMapper <WebStoreData.Models.Subcategory, WebStore.Model.Subcategory>(new DefaultMapConfig().IgnoreMembers <WebStoreData.Models.Subcategory, WebStore.Model.Subcategory>(new [] { "Products" }));

            foreach (var sectionItem in sections)
            {
                WebStore.Model.Section section = sectionMapper.Map(sectionItem);
                productViewModel.Sections.Add(section);
            }

            foreach (var categoryItem in categories)
            {
                WebStore.Model.Category category = categoryMapper.Map(categoryItem);
                productViewModel.Categories.Add(category);
            }

            foreach (var subcategoryItem in subcategories)
            {
                WebStore.Model.Subcategory subcategory = subcategoryMapper.Map(subcategoryItem);
                productViewModel.Subcategories.Add(subcategory);
            }

            foreach (var item in products)
            {
                WebStore.Model.Product product = productMapper.Map(item);

                product.Descriptions      = new List <ProductDescription>();
                product.ShortDescriptions = new List <string>();
                product.Pictures          = new List <string>();
                int sectionId = 0;
                foreach (var subcategory in subcategories)
                {
                    if (item.SubcategoryId == subcategory.SubcategoryId)
                    {
                        product.Subcategory = subcategory.Name;
                    }
                }

                foreach (var category in categories)
                {
                    if (item.CategoryId == category.CategoryId)
                    {
                        product.Category = category.Name;
                        sectionId        = category.SectionId;
                    }
                }

                foreach (var section in sections)
                {
                    if (sectionId == section.SectionId)
                    {
                        product.Section = section.Name;
                    }
                }

                foreach (var description in item.ProductDescriptions)
                {
                    if (description.IsShort)
                    {
                        string shortDescription = description.Name + ":" + description.Text;
                        product.ShortDescriptions.Add(shortDescription);
                    }
                    else
                    {
                        WebStore.Model.ProductDescription productDescription = productDescriptionMapper.Map(description);
                        product.Descriptions.Add(productDescription);
                    }
                }


                foreach (var picture in item.ProductPictures)
                {
                    product.Pictures.Add(picture.Picture);
                }
                productViewModel.Products.Add(product);
            }
            return(productViewModel);
        }
        public ProductListing GetProductListing()
        {
            ProductListing productListing = new ProductListing();

            productListing.Sections = new List <Section>();
            SectionRepository sectionRepository = new SectionRepository();

            List <WebStoreData.Models.Section> sectionsDB = sectionRepository.GetSections().ToList();



            foreach (var sectionDB in sectionsDB)
            {
                WebStore.Models.Section section = new Section();
                section.Name       = sectionDB.Name;
                section.IsLongText = sectionDB.IsLongText;
                section.SectionId  = sectionDB.SectionId;
                section.Url        = sectionDB.Url;
                section.Order      = sectionDB.Order;
                productListing.Sections.Add(section);
                section.Categories = new List <Category>();
                foreach (var categoryDB in sectionDB.Categories)
                {
                    WebStore.Models.Category category = new Category();
                    category.Name       = categoryDB.Name;
                    category.SectionId  = categoryDB.SectionId;
                    category.CategoryId = categoryDB.CategoryId;
                    category.Url        = categoryDB.Url;
                    if (category.SectionId == section.SectionId)
                    {
                        section.Categories.Add(category);
                    }
                    category.SubCategories = new List <Subcategory>();
                    foreach (var subcategoryDB in categoryDB.Subcategories)
                    {
                        WebStore.Models.Subcategory subcategory = new Subcategory();
                        subcategory.Name          = subcategoryDB.Name;
                        subcategory.Image         = subcategoryDB.Image;
                        subcategory.CategoryId    = subcategoryDB.CategoryId;
                        subcategory.SubcategoryId = subcategoryDB.SubcategoryId;
                        subcategory.Url           = subcategoryDB.Url;
                        if (subcategory.CategoryId == category.CategoryId)
                        {
                            category.SubCategories.Add(subcategory);
                        }
                        subcategory.Products = new List <Product>();
                        foreach (var productDB in subcategoryDB.Products)
                        {
                            WebStore.Models.Product product = new Product();
                            product.Name          = productDB.Name;
                            product.Price         = productDB.Price;
                            product.Image         = productDB.Image;
                            product.Rating        = productDB.Rating;
                            product.SubcategoryId = productDB.SubcategoryId;
                            product.ProductId     = productDB.ProductId;
                            if (product.SubcategoryId == subcategory.SubcategoryId)
                            {
                                subcategory.Products.Add(product);
                            }
                            product.Descriptions = new List <ProductDescription>();
                            //product.ShortDiscription=new List<ProductDescription>();
                            product.Pictures = new List <string>();
                            foreach (var productDescriptionDB in productDB.ProductDescriptions)
                            {
                                WebStore.Models.ProductDescription productDescription = new  WebStore.Models.ProductDescription();

                                productDescription.Name      = productDescriptionDB.Name;
                                productDescription.Text      = productDescriptionDB.Text;
                                productDescription.IsShort   = productDescriptionDB.IsShort;
                                productDescription.ProductId = productDescriptionDB.ProductId;
                                product.Descriptions.Add(productDescription);

                                if (productDescription.IsShort == true)
                                {
                                    string shortDescription = productDescriptionDB.Name + ":" + productDescriptionDB.Text;
                                    product.ShortDescriptions.Add(shortDescription);
                                }
                            }

                            foreach (var productPictureDB in productDB.ProductPictures)
                            {
                                product.Pictures.Add(productPictureDB.Picture);
                            }
                        }
                    }
                }
            }
            productListing.Sections = productListing.Sections.OrderBy(x => x.Order).ToList();
            return(productListing);
        }