public async Task <OrderDTO> AddOrder(OrderDTO order)
        {
            if (order.Frequency != null)
            {
                order.IsActive = true;
            }

            var model = _mapper.Map <Order>(order);

            await _context.AddAsync(model);

            await _context.SaveChangesAsync();

            var productList = new List <ProductList>();

            foreach (var id in order.Products.Select(p => p.Id).ToArray())
            {
                productList.Add(new ProductList()
                {
                    ProductId = id, OrderId = model.Id
                });
            }

            await _context.ProductLists.AddRangeAsync(productList);

            await _context.SaveChangesAsync();

            return(_mapper.Map <OrderDTO>(model));
        }
        public async Task <CategoryDTO> AddCategory(CategoryDTO category)
        {
            var model = _mapper.Map <Category>(category);

            await _context.AddAsync(model);

            await _context.SaveChangesAsync();

            return(_mapper.Map <CategoryDTO>(model));
        }
Beispiel #3
0
        public async Task <ProductDTO> AddProduct(ProductDTO modelDto)
        {
            var model = _mapper.Map <Product>(modelDto);

            await _context.AddAsync(model);

            await _context.SaveChangesAsync();

            return(_mapper.Map <ProductDTO>(model));
        }
Beispiel #4
0
        public async Task <IEnumerable <OrderDTO> > AddProducts(Guid[] productsId, Guid orderId)
        {
            var productList = new List <ProductList>();

            foreach (var id in productsId)
            {
                productList.Add(new ProductList()
                {
                    Id = id, OrderId = id
                });
            }

            await _context.ProductLists.AddRangeAsync(productList);

            await _context.SaveChangesAsync();

            return(_mapper.Map <List <OrderDTO> >(_context.Orders.ToList()));
        }
Beispiel #5
0
        public async Task <BoxDTO> UpdateBox(Guid id, BoxDTO modelDto)
        {
            var model = _mapper.Map <Box>(modelDto);

            model.Id = id;

            _context.Boxes.Update(model);

            await _context.SaveChangesAsync();

            return(_mapper.Map <BoxDTO>(model));
        }
Beispiel #6
0
        public static async Task EnsureDatabaseInitialized(IServiceScope serviceScope)
        {
            ShopOnWheelsDbContext context = serviceScope.ServiceProvider.GetRequiredService <ShopOnWheelsDbContext>();

            bool isFirstLaunch = !(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists();

            context.Database.Migrate();

            if (isFirstLaunch)
            {
                await SeedRoles(context);
                await SeedAdmin(serviceScope);
                await AddTestData(context);
            }

            await context.SaveChangesAsync();

            context.Dispose();
        }