Пример #1
0
        public ShipDTO Add(ShipDTO shipDTO)
        {
            var ship = shipDTO.ToModel();

            ship.Id      = IdentityGenerator.NewSequentialGuid();
            ship.Created = DateTime.UtcNow;

            if (ship.Name.IsNullOrBlank())
            {
                throw new DefinedException(CommonMessageResources.Name_Empty);
            }

            if (_Repository.Exists(ship))
            {
                throw new DataExistsException(string.Format(BaseMessagesResources.Ship_Exists_WithValue, ship.Name));
            }

            var ruleName = CommonMessageResources.SerialNumberRule_Ship;
            var snRule   = SerialNumberRuleQuerier.FindBy(ruleName);

            if (snRule == null)
            {
                throw new DataNotFoundException(string.Format(BaseMessagesResources.SerialNumberRule_NotExists_WithValue, ruleName));
            }
            ship.Sn = SerialNumberGenerator.GetSerialNumber(snRule.Prefix, snRule.UseDateNumber, snRule.NumberLength);

            _Repository.Add(ship);

            #region 操作日志

            var shipDto = ship.ToDto();

            OperateRecorder.RecordOperation(shipDto.Sn,
                                            BaseMessagesResources.Add_Ship,
                                            shipDto.GetOperationLog());

            #endregion

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(ship.ToDto());
        }