Exemplo n.º 1
0
        /// <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));
        }