Ejemplo n.º 1
0
        public async Task <List <InventoryItemDetails> > CreateItems(List <InventoryItemDetails> items, User activeDev)
        {
            var newTypeItems = items
                               .Where(iid => iid.Item.ItemTypeId <= 0);

            var newTypes = newTypeItems
                           .GroupBy(item => new { item.ItemType.Name, item.ItemType.Description })
                           .Select(group => group.First().ItemType);


            List <int> newItemIds = new List <int>(items.Count);

            using (var trans = TransactionScopeFactory.Create())
            {
                List <int> newTypeIds = new List <int>(newTypes.Count());
                foreach (var type in newTypes)
                {
                    int newTypeId = await ConfigRepo.CreateItemType(type);

                    type.Id = newTypeId;
                    newTypeIds.Add(newTypeId);
                }
                foreach (var item in newTypeItems)
                {
                    item.Item.ItemTypeId = item.ItemType.Id;
                }
                foreach (var item in items)
                {
                    newItemIds.AddRange(await InventoryRepo.CreateItems(item.Item.ItemTypeId, null));
                }
                trans.Complete();
            }
            var iids = (await InventoryRepo.RetrieveFullItemsByIds(newItemIds.ToArray())).AsList();

            return(iids);
        }