public bool Save(List <string> data)
        {
            if (data == null)
            {
                return(false);
            }
            List <Product> products = data.Select(x => new Product
            {
                Id   = Guid.NewGuid(),
                Code = x
            }).ToList();

            using (DemoContext context = new DemoContext())
            {
                context.Products.DeleteFromQuery();
                context.BulkInsert(products);
            }
            return(true);
        }
        public bool Save(List <string> warehouseData)
        {
            if (warehouseData == null)
            {
                return(false);
            }
            List <Warehouse> warehouses = warehouseData.Select(x => new Warehouse
            {
                Id   = Guid.NewGuid(),
                Code = x
            }).ToList();

            using (DemoContext context = new DemoContext())
            {
                context.Products.DeleteFromQuery();
                context.BulkInsert(warehouses);
            }
            return(true);
        }
Example #3
0
        public bool Save(List <InventoryEntity> list)
        {
            if (list == null)
            {
                return(false);
            }
            List <Inventory> inventories = list.Select(x => new Inventory
            {
                CategoryId  = x.CategoryId,
                ProductId   = x.ProductId,
                WarehouseId = x.WarehouseId,
                Quantity    = x.Quantity
            }).ToList();

            using (var context = new DemoContext())
            {
                context.Inventories.DeleteFromQuery();
                context.BulkInsert(inventories);
            }
            return(true);
        }
        public bool Save(List <CategoryEntity> data)
        {
            if (data == null)
            {
                return(false);
            }
            List <Category> categories = data.Select(x => new Category
            {
                Id       = x.Id,
                Code     = x.Code,
                ParentId = x.ParentId,
                Path     = x.CategoryPath
            }).ToList();

            using (DemoContext context = new DemoContext())
            {
                context.Categories.DeleteFromQuery();
                context.BulkInsert(categories);
            }
            return(true);
        }
Example #5
0
        public void Map(List <InventoryEntity> inventoryEntities)
        {
            DemoContext context = new DemoContext();

            Dictionary <string, Guid> categories = context.Categories.ToDictionary(x => x.Path, x => x.Id);
            Dictionary <string, Guid> products   = context.Products.ToDictionary(x => x.Code, x => x.Id);
            Dictionary <string, Guid> warehouses = context.Warehouses.ToDictionary(x => x.Code, x => x.Id);

            Parallel.ForEach(inventoryEntities, inventoryEntity =>
            {
                if (categories.ContainsKey(inventoryEntity.CategoryPath))
                {
                    inventoryEntity.CategoryId = categories[inventoryEntity.CategoryPath];
                }
                if (products.ContainsKey(inventoryEntity.ProductCode))
                {
                    inventoryEntity.ProductId = products[inventoryEntity.ProductCode];
                }
                if (warehouses.ContainsKey(inventoryEntity.WarehouseCode))
                {
                    inventoryEntity.WarehouseId = warehouses[inventoryEntity.WarehouseCode];
                }
            });
        }