public StockMovement Save() { StockMovement stockMovement = null; var session = NHibernateSessionManager.GetLocalSession(); session.DoTransactional(sess => { stockMovement = new StockMovement( _form.StockMovementType, _form.MovementRemark, _form.MovementReference ); foreach (var dto in _form.StockMovementItemDtos) { stockMovement.AddMovementItem(dto.Inventory, dto.Storage, dto.Quantity); } stockMovement = _movementRepository.Insert(stockMovement); }); return(stockMovement); }
public Inventory Save() { Inventory inventory = null; var session = NHibernateSessionManager.GetLocalSession(); session.DoTransactional(sess => { inventory = _inventoryRepository.Insert( new Inventory( _form.Code, _form.InventoryName, _form.Description, _form.BuyPrice, _form.UnitOfMeasurement ) ); if (_form.InventoryStorageDto.Count > 0) { var stockMovement = new StockMovement( StockMovementType.INITIALBALANCE, @"CREATED AUTOMATICALLY FROM ADD NEW INVENTORY"); foreach (var inventoryStorageDto in _form.InventoryStorageDto) { stockMovement.AddMovementItem(inventory, inventoryStorageDto.Storage, inventoryStorageDto.Quantity); _storageRepository.Update(inventoryStorageDto.Storage); } _stockMovementRepository.Insert(stockMovement); } if (_form.AddAsProduct) { var product = new Product( _form.ProductCode, inventory, _form.ProductCategory, _form.SellPrice ) { Volume = _form.Volume }; _productRepository.Insert(product); } if (_form.AddAsMerchandise) { var merchandise = new Merchandise( _form.MerchandiseCode, inventory, _form.MerchandisePoint, 1, inventory.Name, inventory.Description ); _merchandiseRepository.Insert(merchandise); } }); return(inventory); }