public async Task <bool> Handle(ChangeMeteringUnitCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                await NotifyValidationErrors(request);

                return(false);
            }
            var category = await _assetCategoryRepository.GetByIdAsync(request.AssetCategoryId);

            category.ChangeUnit(request.AssetMeteringUnit);
            if (await CommitAsync())
            {
                await Bus.RaiseEventAsync(new CategoryMeteringUnitChangedEvent(_user.OrgId));

                return(true);
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// 新增一个资产申请(AssetApply)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <bool> Handle(CreateAssetApplyCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                await NotifyValidationErrors(request);

                return(false);
            }

            var assetCategory = await _assetCategoryRepository.GetByIdAsync(request.AssetCategoryId);

            if (assetCategory == null)
            {
                await Bus.RaiseEventAsync(new DomainNotification("系统错误", "传入的资产分类参数有误,请联系管理员"));

                return(false);
            }
            var targetOrg = await _organizationRepository.GetByIdAsync(request.TargetOrgId);

            if (targetOrg == null)
            {
                await Bus.RaiseEventAsync(new DomainNotification("系统错误", "查找目标机构信息为空,请联系管理员"));

                return(false);
            }

            var assetApply = await _assetDomainService.CreateAssetApply(_user,
                                                                        targetOrg,
                                                                        assetCategory.Id,
                                                                        assetCategory.AssetThirdLevelCategory,
                                                                        request.Message);

            if (await CommitAsync())
            {
                await Bus.RaiseEventAsync(new AssetApplyCreatedEvent(
                                              _user.OrgId,
                                              assetApply,
                                              request.Message));

                return(true);
            }
            return(false);
        }
示例#3
0
        public async Task <bool> Handle(StoreAssetWithOutFileCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                await NotifyValidationErrors(request);

                return(false);
            }
            var category = await _assetCategoryRepository.GetByIdAsync(request.AssetCategoryId);

            if (category == null)
            {
                await Bus.RaiseEventAsync(new DomainNotification("系统错误", "未找到相关分类,请联系管理员"));

                return(false);
            }

            var tagNumberPrefix       = request.StartTagNumber.Substring(0, 10);
            var startCountParseResult = int.TryParse(request.StartTagNumber.Substring(10, 5), out var startCount);

            if (!startCountParseResult)
            {
                await Bus.RaiseEventAsync(new DomainNotification("操作错误", "录入的起始标签号有误,请重新填写"));

                return(false);
            }
            var endCountParseResult = int.TryParse(request.EndTagNumber.Substring(10, 5), out var endCount);

            if (!endCountParseResult)
            {
                await Bus.RaiseEventAsync(new DomainNotification("操作错误", "录入的结束标签号有误,请重新填写"));

                return(false);
            }

            for (var operationCount = startCount; operationCount <= endCount; operationCount++)
            {
                var tagNumber       = new StringBuilder();
                var tagNumberSuffix = new StringBuilder(operationCount.ToString());
                while (tagNumberSuffix.Length != 5)
                {
                    tagNumberSuffix.Insert(0, '0');
                }

                tagNumber.Append(tagNumberPrefix);
                tagNumber.Append(tagNumberSuffix);
                var asset = new Asset
                {
                    AssetStatus            = AssetStatus.在库,
                    Id                     = Guid.NewGuid(),
                    AssetLocation          = request.AssetLocation,
                    AssetCategoryId        = category.Id,
                    AssetName              = request.AssetName,
                    Brand                  = request.Brand,
                    AssetDescription       = request.AssetDescription,
                    AssetType              = request.AssetType,
                    AssetTagNumber         = tagNumber.ToString(),
                    InStoreDateTime        = DateTime.Now,
                    LastModifyDateTime     = DateTime.Now,
                    LatestDeployRecord     = request.Message,
                    CreateDateTime         = request.CreateDateTime,
                    OrganizationBelongedId = _user.OrgId,
                    StoredOrgIdentifier    = _user.OrgIdentifier,
                    StoredOrgName          = _user.OrgNam
                };
                await _assetRepository.AddAsync(asset);
            }

            if (await CommitAsync())
            {
                return(true);
            }
            return(false);
        }