private void AddBoxWithoutProduct(string[] boxesChildrenID, Box box) { var boxesChildren = _unitOfWork.Repository <Box>().FindAll(x => boxesChildrenID.Any(id => new Guid(id) == x.Id)).ToList(); var boxesChildrenWithFather = box.AddChildren(boxesChildren); box.Destructor(); _unitOfWork.Repository <Box>().Add(box); _unitOfWork.Repository <Box>().UpdateRange(boxesChildrenWithFather); }
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); } }