private static void SeedProducts(GroceryStoreDbContext context, ProductDto[] productDtos) { var productsToCreate = new List <Product>(); foreach (var productDto in productDtos) { var manufacturer = context.Manufacturers.SingleOrDefault(x => x.Name == productDto.ManufacturerName); if (manufacturer != null) { var manufacturerId = manufacturer.Id; var product = new Product { Name = productDto.Name, PictureUrl = productDto.PictureUrl, Price = productDto.Price, Discount = productDto.Discount, Kind = productDto.Kind, Type = productDto.Type, Weight = productDto.Weight, ManufacturerId = manufacturerId }; productsToCreate.Add(product); } } context.Products.AddRange(productsToCreate); context.SaveChanges(); }
protected BaseEFService( GroceryStoreDbContext dbContext, IMapper mapper) { DbContext = dbContext; Mapper = mapper; }
public ShoppingCartController(IShoppingCartManager shoppingCartManager, GroceryStoreDbContext dbContext, UserManager <User> userManager) { this._shoppingCartManager = shoppingCartManager; this._dbContext = dbContext; this._userManager = userManager; }
public AdminUsersService(GroceryStoreDbContext dbContext, IMapper mapper, UserManager <User> userManager, SignInManager <User> signInManager) : base(dbContext, mapper) { this._userManager = userManager; this._signInManager = signInManager; }
private static void SeedManufacturers(GroceryStoreDbContext context, ManufacturerDto[] manufacturerDtos) { var manufacturersToCreate = manufacturerDtos .Select(t => new Manufacturer { Name = t.Name, LogoUrl = t.LogoUrl }) .ToArray(); context.Manufacturers.AddRange(manufacturersToCreate); context.SaveChanges(); }
public void InitializeTests() { this._dbContext = MockDbContext.GetContext(); this._mapper = MockAutoMapper.GetAutoMapper(); this._service = new AdminManufacturersService(this._dbContext, this._mapper); this._dbContext.Manufacturers.Add(new Manufacturer() { Id = 1, Name = string.Format(TestsConstants.Manufacturer, 1), LogoUrl = string.Format(TestsConstants.Logo, 1) }); this._dbContext.SaveChanges(); }
public void Init() { Random r = new Random(); var databaseName = $"db_Test{r.Next(1, 100000000)}"; var options = new DbContextOptionsBuilder <GroceryStoreDbContext>() .UseInMemoryDatabase(databaseName: databaseName) .Options; _db = new GroceryStoreDbContext(options); _service = new GroceryStoreService(_db); var jObjects = JObject.Parse(File.ReadAllText("database.json")); //Customers JArray customerArray = jObjects.GetValue("customers") as JArray; var customers = customerArray.Select(p => new Customer { Id = (int)p["id"], Name = (string)p["name"] }); _db.Customers.AddRange(customers); //Orders var orders = new List <Order>(); JArray orderArray = jObjects.GetValue("orders") as JArray; _db.Orders.AddRange(orderArray.Select(p => p.ToObject <Order>())); //Products var productsArray = jObjects.GetValue("products") as JArray; var products = productsArray.Select(p => new Product { Id = (int)p["id"], Description = (string)p["description"], Price = (double)p["price"] }); _db.Products.AddRange(products); //"Save" everything in-memory _db.SaveChanges(); }
public void InitializeTests() { this._dbContext = MockDbContext.GetContext(); this._mapper = MockAutoMapper.GetAutoMapper(); this._service = new AdminProductsService(this._dbContext, this._mapper); this._dbContext.Manufacturers.Add(new Manufacturer() { Id = 1, Name = string.Format(TestsConstants.Manufacturer, 1) }); this._dbContext.SaveChanges(); this._dbContext.Products.Add(new Product() { Id = 1, Name = string.Format(TestsConstants.Product, 1), Type = string.Format(TestsConstants.Type, 1), ManufacturerId = 1 }); this._dbContext.SaveChanges(); }
private static void SeedImages(GroceryStoreDbContext context, ImageDto[] imagesDtos) { var imagesToCreate = new List <Image>(); foreach (var imageDto in imagesDtos) { var product = context.Products.SingleOrDefault(x => x.Name == imageDto.ProductName); if (product != null) { var productId = product.Id; var image = new Image { Url = imageDto.Url, ProductId = productId }; imagesToCreate.Add(image); } } context.Images.AddRange(imagesToCreate); context.SaveChanges(); }
public GoodsWriteOffOwnRepository(GroceryStoreDbContext context) : base(context) { }
public ProductionContentsRepository(GroceryStoreDbContext context) : base(context) { }
public AdminManufacturersService(GroceryStoreDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public ProductRepository(GroceryStoreDbContext dbContext) { _dbContext = dbContext; }
public ConsignmentRepository(GroceryStoreDbContext context) : base(context) { }
public AdminImagesService(GroceryStoreDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public BasketRepository(GroceryStoreDbContext context) : base(context) { }
public RoleRepository(GroceryStoreDbContext context) : base(context) { }
public WriteOffReasonRepository(GroceryStoreDbContext context) : base(context) { }
public GroceryStoreRepository(GroceryStoreDbContext groceryStoreDbContext) { _groceryStoreDbContext = groceryStoreDbContext; }
public GoodsRepository(GroceryStoreDbContext context) : base(context) { }
public ProductsService(GroceryStoreDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public TypesService(GroceryStoreDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public DeliveryRepository(GroceryStoreDbContext context) : base(context) { }
public CountryRepository(GroceryStoreDbContext context) : base(context) { }
public ProviderRepository(GroceryStoreDbContext context) : base(context) { }
protected BaseRepository(GroceryStoreDbContext context) { _context = context; }
public ManufacturerProductsServices(GroceryStoreDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public GoodsInMarketOwnRepository(GroceryStoreDbContext context) : base(context) { }
public EmployeeRepository(GroceryStoreDbContext context) : base(context) { }