public void AddBoxStockWithBoxes(Guid boxTypeID, Guid trackingTypeID, Guid clientID, Guid boxTypeChildID, int quantity) { try { var boxesChildrem = _unitOfWork.RepositoryCustom <IProductRepository>().GetBoxesInStockByBoxTypeIDAndClientID(boxTypeChildID, clientID); var boxType = _unitOfWork.Repository <BoxType>().GetById(boxTypeID); List <Box> boxesUpdateChildrem = new List <Box>(); IList <Box> boxes = new List <Box>(); for (int i = 0; i < quantity; i++) { var updateList = boxesChildrem.Where(x => !boxesUpdateChildrem.Any(p => p.Id == x.Id)).Take(boxType.MaxProductsItems).ToList(); Box box = Box.FactoryCreate(boxTypeID, boxType, i); box.FlowStep.SetInStock(); boxesUpdateChildrem.AddRange(box.AddChildren(updateList)); box.AddTracking(trackingTypeID, clientID); box.BoxType = null; box.BoxesChildren = null; boxes.Add(box); } _unitOfWork.Repository <Box>().AddRange(boxes); _unitOfWork.Repository <Box>().UpdateRange(boxesUpdateChildrem); _unitOfWork.CommitSync(); } catch (CustomException exc) { throw exc; } catch (Exception ex) { throw CustomException.Create <ProductApplicationService>("Unexpected error fetching Add Stock Product", nameof(this.AddStockProduct), ex); } }
public void AddBoxStockWithProductItems(Guid boxTypeID, Guid trackingTypeID, Guid clientID, Guid productID, int quantity) { try { var productsItems = _unitOfWork.RepositoryCustom <IProductRepository>().GetAvailableStockProductItemsByClientIDAndProductID(productID, clientID); var boxType = _unitOfWork.Repository <BoxType>().GetById(boxTypeID); List <ProductItem> productsItemsUpdate = new List <ProductItem>(); IList <Box> boxes = new List <Box>(); for (int i = 0; i < quantity; i++) { var updateList = productsItems.Where(x => !productsItemsUpdate.Any(p => p.Id == x.Id)).Take(boxType.MaxProductsItems).ToList(); productsItemsUpdate.AddRange(updateList); Box box = Box.FactoryCreate(boxTypeID, boxType, i, productID); box.FlowStep.SetInStock(); // box.LoadProductItems(updateList); box.AddTracking(trackingTypeID, clientID); box.BoxType = null; boxes.Add(box); } _unitOfWork.Repository <Box>().AddRange(boxes); _unitOfWork.Repository <ProductItem>().UpdateRange(productsItemsUpdate); _unitOfWork.CommitSync(); } catch (CustomException exc) { throw exc; } catch (Exception ex) { throw CustomException.Create <ProductApplicationService>("Unexpected error fetching Add Stock Product", nameof(this.AddStockProduct), ex); } }