public async Task <Result <int> > Handle(CreateStepCommand request, CancellationToken cancellationToken) { var journey = await _journeyRepository.GetByIdAsync(request.JourneyId); var mode = await _modeRepository.GetByIdAsync(request.ModeId); var responsible = await _responsibleRepository.GetByCodeAsync(request.ResponsibleCode); if (responsible == null) { responsible = await CreateResponsibleAsync(request.ResponsibleCode); if (responsible == null) { return(new NotFoundResult <int>($"Responsible with code {request.ResponsibleCode} not found")); } // must save new Responsible to get id of it await _unitOfWork.SaveChangesAsync(cancellationToken); } var step = new Step(_plantProvider.Plant, request.Title, mode, responsible) { AutoTransferMethod = request.AutoTransferMethod }; journey.AddStep(step); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <int>(step.Id)); }
public async Task <Result <string> > Handle(UpdateStepCommand request, CancellationToken cancellationToken) { var journey = await _journeyRepository.GetByIdAsync(request.JourneyId); var step = journey.Steps.Single(s => s.Id == request.StepId); var mode = await _modeRepository.GetByIdAsync(request.ModeId); var responsible = await _responsibleRepository.GetByCodeAsync(request.ResponsibleCode); if (responsible == null) { responsible = await CreateResponsibleAsync(request.ResponsibleCode); if (responsible == null) { return(new NotFoundResult <string>($"Responsible with code {request.ResponsibleCode} not found")); } // must save new Responsible to get id of it await _unitOfWork.SaveChangesAsync(cancellationToken); } step.SetMode(mode); step.SetResponsible(responsible); step.Title = request.Title; step.AutoTransferMethod = request.AutoTransferMethod; step.SetRowVersion(request.RowVersion); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <string>(step.RowVersion.ConvertToString())); }
public async Task <Result <string> > Handle(UnvoidModeCommand request, CancellationToken cancellationToken) { var mode = await _modeRepository.GetByIdAsync(request.ModeId); mode.IsVoided = false; mode.SetRowVersion(request.RowVersion); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <string>(mode.RowVersion.ConvertToString())); }
public async Task <Result <Unit> > Handle(DeleteModeCommand request, CancellationToken cancellationToken) { var mode = await _modeRepository.GetByIdAsync(request.ModeId); mode.SetRowVersion(request.RowVersion); _modeRepository.Remove(mode); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <Unit>(Unit.Value)); }
public async Task <Result <string> > Handle(UpdateModeCommand request, CancellationToken cancellationToken) { var mode = await _modeRepository.GetByIdAsync(request.ModeId); mode.Title = request.Title; mode.ForSupplier = request.ForSupplier; mode.SetRowVersion(request.RowVersion); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <string>(mode.RowVersion.ConvertToString())); }
public async Task <Result <List <int> > > Handle(CreateTagsCommand request, CancellationToken cancellationToken) { var step = await _journeyRepository.GetStepByStepIdAsync(request.StepId); var reqDefIds = request.Requirements.Select(r => r.RequirementDefinitionId).ToList(); var reqDefs = await _requirementTypeRepository.GetRequirementDefinitionsByIdsAsync(reqDefIds); var mode = await _modeRepository.GetByIdAsync(step.ModeId); var addedTags = new List <Tag>(); var project = await _projectRepository.GetProjectOnlyByNameAsync(request.ProjectName); var tagDetailList = await _tagApiService.GetTagDetailsAsync(_plantProvider.Plant, request.ProjectName, request.TagNos); foreach (var tagNo in request.TagNos) { var tagDetails = tagDetailList.FirstOrDefault(td => td.TagNo == tagNo); if (tagDetails == null) { return(new NotFoundResult <List <int> >($"Details for Tag {tagNo} not found in project {request.ProjectName}")); } // Todo TECH This type of validation should be in validator not in handler. // Since we don't want to ask main api for same data both in validator and here, we do it here only if (mode.ForSupplier && string.IsNullOrEmpty(tagDetails.PurchaseOrderNo)) { return(new NotFoundResult <List <int> >($"Purchase Order for {tagNo} not found in project {request.ProjectName}. Tag can not be in a Supplier step")); } if (project == null) { project = new Project(_plantProvider.Plant, request.ProjectName, tagDetails.ProjectDescription); _projectRepository.Add(project); } var tagToAdd = CreateTag(request, step, tagDetails, reqDefs); project.AddTag(tagToAdd); addedTags.Add(tagToAdd); } // Todo Remove Migration handling when migration period from old to new preservation in ProCoSys is over await _tagApiService.MarkTagsAsMigratedAsync(_plantProvider.Plant, tagDetailList.Select(t => t.Id)); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <List <int> >(addedTags.Select(t => t.Id).ToList())); }