public async Task <GetDocumentQueryResponse> Handle(GetDocumentQuery request, CancellationToken cancellationToken) { var employee = await _employeeService.GetByLogin(request.EmployeeLogin); var attribute = await _attributeInfoService.GetById(request.AttributeInfoId); if (employee == null) { throw new ValidationException("Employee not found."); } if (attribute == null) { throw new ValidationException("Attribute not found."); } if (!_documentService.IsExists(employee, attribute)) { throw new ValidationException("File not found."); } return(new GetDocumentQueryResponse { Document = _documentService.Load(employee, attribute) }); }
public async Task Handle(AddDocumentCommand request, CancellationToken cancellationToken) { var employee = await _employeeService.GetByLogin(request.EmployeeLogin); var attribute = await _attributeInfoService.GetById(request.AttributeInfoId); _documentService.Save(employee, attribute, request.Document); }
public async Task Handle(DeleteDocumentCommand request, CancellationToken cancellationToken) { var employee = await _employeeService.GetByLogin(request.EmployeeLogin).ConfigureAwait(false); var attribute = await _attributeInfoService.GetById(request.AttributeInfoId).ConfigureAwait(false); _documentService.Delete(employee, attribute); }
private async Task CheckAttributeInfo(List <ValidationFailure> list, AddDocumentCommand request) { var attribute = await _attributeInfoService.GetById(request.AttributeInfoId); if (attribute == null) { list.Add("Attribute not 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 }); } }
public async Task <GetAttributeSavingInfoQueryResponse> Handle(GetAttributeSavingInfoQuery request, CancellationToken cancellationToken) { if (!request.Id.HasValue) { return new GetAttributeSavingInfoQueryResponse { Name = string.Empty, Type = AttributeType.String } } ; var attribute = await _attributeInfoService.GetById(request.Id.Value).ConfigureAwait(false); return(new GetAttributeSavingInfoQueryResponse { Name = attribute.Name, Type = attribute.Type }); } }
public async Task Validate(List <ValidationFailure> list, DeleteDocumentCommand request) { if (!await _employeeService.IsExists(request.EmployeeLogin)) { list.Add("Employee not found."); return; } if (!await _attributeInfoService.IsExists(request.AttributeInfoId)) { list.Add("Attribute not found."); } var employee = await _employeeService.GetByLogin(request.EmployeeLogin); var attribute = await _attributeInfoService.GetById(request.AttributeInfoId); if (!_documentService.IsExists(employee, attribute)) { list.Add("Document not found."); } }
public async Task Handle(DeleteAttributeCommand request, CancellationToken cancellationToken) { var attributeInfo = await _attributeInfoService.GetById(request.AttributeInfoId); await _attributeInfoService.Delete(attributeInfo); }