Example #1
0
        private static void SeedProducts(ChameleonStoreContext context, ProductDto[] productDtos)
        {
            var productsToCreate = new List <Product>();

            foreach (var productDto in productDtos)
            {
                var category = context.Categories.SingleOrDefault(x => x.Name == productDto.CategoryName);
                var brand    = context.Brands.SingleOrDefault(x => x.Name == productDto.BrandName);

                if (category != null)
                {
                    var product = new Product
                    {
                        Name        = productDto.Name,
                        ImageURL    = productDto.ImageURL,
                        Price       = productDto.Price,
                        Discount    = productDto.Discount,
                        Condition   = productDto.Condition,
                        Description = productDto.Description,
                        BrandId     = brand.Id,
                        CategoryId  = category.Id,
                        Views       = productDto.Views
                    };

                    productsToCreate.Add(product);
                }
            }

            context.Products.AddRange(productsToCreate);
            context.SaveChanges();
        }
Example #2
0
 protected BaseEFService(
     ChameleonStoreContext context,
     IMapper mapper)
 {
     this.Context = context;
     this.Mapper  = mapper;
 }
Example #3
0
 public AdminProductServiceTest()
 {
     this.context             = MockDbContext.GetContext();
     this.mapper              = MockAutoMapper.GetAutoMapper();
     this.dropDownService     = new DropDownListService(this.context, this.mapper);
     this.productService      = new ProductService(this.context, this.mapper);
     this.adminProductService = new AdminProductService(this.context, this.mapper, this.productService, this.dropDownService);
 }
Example #4
0
 public RoleService(
     ChameleonStoreContext context,
     IMapper mapper,
     IDropDownListable dropDownService)
     : base(context, mapper)
 {
     this.dropDownService = dropDownService;
 }
Example #5
0
 public AdminProductService(
     ChameleonStoreContext context,
     IMapper mapper,
     IProductService products,
     IDropDownListable dropDownService)
     : base(context, mapper)
 {
     this.products        = products;
     this.dropDownService = dropDownService;
 }
Example #6
0
 public ProductsController(
     ChameleonStoreContext context,
     IMapper mapper,
     IAdminProductService products,
     IDropDownListable dropDownService)
 {
     this.context         = context;
     this.mapper          = mapper;
     this.products        = products;
     this.dropDownService = dropDownService;
 }
Example #7
0
        private static void SeedBrands(ChameleonStoreContext context, BrandDto[] brandDtos)
        {
            var brandsToCreate = brandDtos
                                 .Select(c => new Brand
            {
                Name = c.Name
            })
                                 .ToArray();

            context.Brands.AddRange(brandsToCreate);
            context.SaveChanges();
        }
Example #8
0
        private static void SeedCategories(ChameleonStoreContext context, CategoryDto[] categoryDtos)
        {
            var categoriesToCreate = categoryDtos
                                     .Select(c => new Category
            {
                Name = c.Name
            })
                                     .ToArray();

            context.Categories.AddRange(categoriesToCreate);
            context.SaveChanges();
        }
Example #9
0
 public ProductService(
     ChameleonStoreContext context,
     IMapper mapper)
     : base(context, mapper)
 {
 }
Example #10
0
 public OrderService(
     ChameleonStoreContext context,
     IMapper mapper)
     : base(context, mapper)
 {
 }
Example #11
0
 public ProductServiceTest()
 {
     this.context  = MockDbContext.GetContext();
     this.mapper   = MockAutoMapper.GetAutoMapper();
     this.products = new ProductService(this.context, this.mapper);
 }
Example #12
0
 public DropDownListService(
     ChameleonStoreContext context,
     IMapper mapper)
     : base(context, mapper)
 {
 }