示例#1
0
        public async Task Validate(List <ValidationFailure> list, SaveAttributeCommand request)
        {
            list.NotNullOrEmpty("Name", request.Name);

            if (await _attributeInfoService.IsExists(request.Name).ConfigureAwait(false))
            {
                list.Add("Attribute with same name already exists.");
            }

            if (request.Id.HasValue)
            {
                if (!await _attributeInfoService.IsExists(request.Id.Value))
                {
                    list.Add("Attribute with same id wasn't found.");
                }
            }
        }
        public async Task Handle(SaveAttributeCommand request, CancellationToken cancellationToken)
        {
            if (request.Id.HasValue)
            {
                var attribute = await _attributeInfoService.GetById(request.Id.Value);

                attribute.Name = request.Name;
                attribute.Type = request.Type;

                await _attributeInfoService.Update(attribute);
            }
            else
            {
                await _attributeInfoService.Create(new AttributeInfo
                {
                    Name = request.Name,
                    Type = request.Type
                });
            }
        }