public async Task <CostMatrixReference> Handle(CreateCostMatrixWithParametersCommand request, CancellationToken cancellationToken) { _unitOfWork.BeginTransaction(); try { var costMatrix = _mapper.Map <CostMatrix>(request); var newCostmatrixId = await _costmatrixRepository.CreateCostMatrixAsync(costMatrix, request.Company); // Insert the tags on common service. EntityTagListDto requestTags = new EntityTagListDto(); requestTags.EntityExternalId = newCostmatrixId.ToString(CultureInfo.InvariantCulture); requestTags.EntityTypeName = TagsEntityTypes.COSTMATRIX; requestTags.Tags = new List <TagDto>(); if (request.Tags != null && request.Tags.Any()) { foreach (TagLine itemTagLine in request.Tags) { TagDto tag = new TagDto() { TagValueId = itemTagLine.Id, TypeName = itemTagLine.TypeName }; requestTags.Tags.Add(tag); } } await _tagsService.CreateTagsAsync(requestTags, request.Company); _logger.LogInformation("New cost matrix created with id {Atlas_CostMatrixId}.", newCostmatrixId); _unitOfWork.Commit(); return(new CostMatrixReference { CostMatrixId = newCostmatrixId }); } catch { _unitOfWork.Rollback(); throw; } }
/// <inheritdoc/> public async Task <bool> CreateOrUpdateTagsForContractAdviceTemplatesAsync(string company, IEnumerable <CreateOrUpdateTagsForTemplatesDto> tagsForTemplates) { foreach (var item in tagsForTemplates) { EntityTagListDto currentItem = new EntityTagListDto() { EntityId = item.EntityId, EntityExternalId = item.EntityExternalId, EntityTypeName = TagsEntityTypes.CONTRACTADVICETEMPLATE, IsDeactivated = item.IsDeactivated, Tags = (List <TagDto>)item.Tags }; // New entity if (currentItem.EntityId < 0) { await this._tagsService.CreateTagsAsync(currentItem, company); } else { var oldExternalId = (await _tagsService.GetEntityByIdAsync(new EntityTagListDto { EntityId = currentItem.EntityId })).EntityExternalId; // Template column hasn't changed if (currentItem.EntityExternalId == oldExternalId) { await _tagsService.UpdateTagsAsync(currentItem, company); } // Template column has changed else { await _tagsService.DeleteEntityAsync(company, currentItem.EntityId); await _tagsService.CreateTagsAsync(currentItem, company); } } } return(await Task.FromResult(true)); }