Пример #1
0
        /// <summary>
        /// Saves a single <see cref="IShipment"/> object
        /// </summary>
        /// <param name="shipment">The <see cref="IShipment"/> to save</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        public void Save(IShipment shipment, bool raiseEvents = true)
        {
            if (!((Shipment)shipment).HasIdentity && shipment.ShipmentNumber <= 0)
            {
                // We have to generate a new 'unique' invoice number off the configurable value
                ((Shipment)shipment).ShipmentNumber = _storeSettingService.GetNextShipmentNumber();
            }

            var includesStatusChange = ((Shipment)shipment).IsPropertyDirty("ShipmentStatus") &&
                                       shipment.HasIdentity;

            if (raiseEvents)
            {
                if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipment>(shipment), this))
                {
                    ((Shipment)shipment).WasCancelled = true;
                    return;
                }

                if (includesStatusChange)
                {
                    StatusChanging.RaiseEvent(new StatusChangeEventArgs <IShipment>(shipment), this);
                }
            }


            if (raiseEvents)
            {
                if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipment>(shipment), this))
                {
                    ((Shipment)shipment).WasCancelled = true;
                    return;
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateShipmentRepository(uow))
                {
                    repository.AddOrUpdate(shipment);
                    uow.Commit();
                }
            }

            if (!raiseEvents)
            {
                return;
            }

            Saved.RaiseEvent(new SaveEventArgs <IShipment>(shipment), this);
            if (includesStatusChange)
            {
                StatusChanged.RaiseEvent(new StatusChangeEventArgs <IShipment>(shipment), this);
            }
        }
Пример #2
0
        public void Can_Get_The_Next_ShipmentNumber()
        {
            var number = _settingsService.GetNextShipmentNumber(1);

            Assert.Greater(number, 1);
        }