Exemple #1
0
 private void CheckListEntitiesByTagsInput(EntityTagListDto tags)
 {
     if (tags == null)
     {
         throw new ArgumentNullException(nameof(tags));
     }
 }
Exemple #2
0
 private void CheckParameter(EntityTagListDto tags)
 {
     if (tags == null)
     {
         throw new ArgumentNullException(nameof(tags));
     }
 }
Exemple #3
0
        private DataTable ConvertToEntityTagsToUDTT(EntityTagListDto entity)
        {
            DataTable udtt = new DataTable();

            udtt.SetTypeName("[CrossCutting].[UDTT_EntityTag]");

            DataColumn entityId = new DataColumn("EntityId", typeof(int));

            udtt.Columns.Add(entityId);

            DataColumn entityExternalId = new DataColumn("EntityExternalId", typeof(string));

            udtt.Columns.Add(entityExternalId);

            DataColumn entityTypeName = new DataColumn("EntityTypeName", typeof(string));

            udtt.Columns.Add(entityTypeName);

            DataColumn isDeactivated = new DataColumn("IsDeactivated", typeof(bool));

            udtt.Columns.Add(isDeactivated);

            DataColumn tagValueId = new DataColumn("TagValueId", typeof(string));

            udtt.Columns.Add(tagValueId);

            DataColumn tagTypeName = new DataColumn("TagTypeName", typeof(string));

            udtt.Columns.Add(tagTypeName);

            if (entity.Tags != null && entity.Tags.Any())
            {
                List <TagDto> splitTags = SplitTags(entity.Tags);
                entity.Tags = splitTags;

                foreach (var tag in entity.Tags)
                {
                    var row = udtt.NewRow();
                    row[entityId]         = entity.EntityId;
                    row[entityExternalId] = entity.EntityExternalId;
                    row[entityTypeName]   = entity.EntityTypeName;
                    row[isDeactivated]    = entity.IsDeactivated;
                    row[tagValueId]       = tag.TagValueId;
                    row[tagTypeName]      = tag.TypeName;
                    udtt.Rows.Add(row);
                }
            }
            else
            {
                var row = udtt.NewRow();
                row[entityId]         = entity.EntityId;
                row[entityExternalId] = entity.EntityExternalId;
                row[entityTypeName]   = entity.EntityTypeName;
                row[isDeactivated]    = entity.IsDeactivated;
                udtt.Rows.Add(row);
            }

            return(udtt);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="companyId"></param>
        /// <param name="listCostMatricesByTags"></param>
        /// <returns></returns>
        public async Task <List <EntitiesBestMatchDto> > ListCostMatricesOrderedByTagsAsync(string companyId, List <TagDto> listCostMatricesByTags)
        {
            EntityTagListDto request = new EntityTagListDto()
            {
                EntityTypeName = TagsEntityTypes.COSTMATRIX,
                Tags           = listCostMatricesByTags
            };

            return(await this._tagsService.ListEntitiesByTagsAsync(request));
        }
        /// <inheritdoc/>
        public async Task <IEnumerable <EntitiesBestMatchDto> > ListContractAdviceTemplatesByTagsAsync(string company, IEnumerable <TagDto> documentTemplateListByTags)
        {
            EntityTagListDto request = new EntityTagListDto()
            {
                EntityTypeName = TagsEntityTypes.CONTRACTADVICETEMPLATE,
                Tags           = (List <TagDto>)documentTemplateListByTags
            };

            return(await this._tagsService.ListEntitiesByTagsAsync(request));
        }
Exemple #6
0
        /// <inheritdoc/>
        public async Task UpdateTagsAsync(EntityTagListDto tags, string company)
        {
            this.CheckParameter(tags);

            var queryParameters = new DynamicParameters();

            queryParameters.Add("@iEntity", ConvertToEntityTagsToUDTT(tags));
            queryParameters.Add("@iCompanyId", company);

            await this.ExecuteNonQueryAsync(StoredProcedureNames.UpdateTags, queryParameters, true).ConfigureAwait(false);
        }
Exemple #7
0
        /// <summary>
        /// Returns a list of Entities ordered by BestMatch
        /// </summary>
        /// <param name="tags">Tags filter.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public async Task <List <EntitiesBestMatchDto> > ListEntitiesByTagsAsync(EntityTagListDto tags)
        {
            this.CheckListEntitiesByTagsInput(tags);

            var queryParameters = new DynamicParameters();

            queryParameters.Add("@iTags", ConvertToEntityTagsToUDTT(tags));

            var result = await this.ExecuteQueryAsync <EntitiesBestMatchDto>(StoredProcedureNames.ListEntitiesByTags, queryParameters).ConfigureAwait(false);

            return(result.ToList());
        }
Exemple #8
0
        public async Task <EntityTagListDto> GetEntityByIdAsync(EntityTagListDto entityId)
        {
            this.CheckListEntitiesByTagsInput(entityId);

            var queryParameters = new DynamicParameters();

            queryParameters.Add("@iEntity", ConvertToEntityTagsToUDTT(entityId));

            var result = await this.ExecuteQueryAsync <EntityTagListDto>(StoredProcedureNames.ListEntitiesById, queryParameters).ConfigureAwait(false);

            return(result.FirstOrDefault());
        }
Exemple #9
0
        public async Task <Unit> Handle(UpdateCostMatrixWithParametersCommand request, CancellationToken cancellationToken)
        {
            _unitOfWork.BeginTransaction();
            try
            {
                var costMatrix = _mapper.Map <CostMatrix>(request);

                foreach (var costMatrixLines in costMatrix.CostMatrixLines)
                {
                    costMatrixLines.CostMatrixId = costMatrix.CostMatrixId;
                }

                await _costmatrixRepository.UpdateCostMatrixAsync(costMatrix, request.Company);


                EntityTagListDto requestTags = new EntityTagListDto();
                requestTags.EntityExternalId = request.CostMatrixId.ToString(CultureInfo.InvariantCulture);
                requestTags.EntityTypeName   = TagsEntityTypes.COSTMATRIX;

                requestTags.Tags = new List <TagDto>();

                foreach (TagLine itemTagLine in request.Tags)
                {
                    TagDto tag = new TagDto()
                    {
                        TagValueId = itemTagLine.Id,
                        TypeName   = itemTagLine.TypeName
                    };
                    requestTags.Tags.Add(tag);
                }

                await _tagsService.UpdateTagsAsync(requestTags, request.Company);

                _logger.LogInformation("Cost matrix with id {Atlas_CostMatrixId} updated.", costMatrix.CostMatrixId);

                _unitOfWork.Commit();

                return(Unit.Value);
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }
Exemple #10
0
        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));
        }