Esempio n. 1
0
        private async Task <string> Create(TagCreateData data)
        {
            var tags = await _context.Where <Tag>(nameof(Tag.Name), data.Name);

            var tag = tags.FirstOrDefault();

            // only create a new tag, if it doesn't already exist
            if (tag != null && !tag.Id.IsNullOrWhitespace())
            {
                return(tag.Id);
            }

            var create = new Tag
            {
                Id        = _idGenerator.New(),
                Name      = data.Name,
                CreatedBy = _userId,
                CreatedAt = DateTime.UtcNow
            };

            await _context.SaveAsync(create);

            Log.DebugFormat("New tag {0} created by user {1}", create.Id, _userId);

            return(create.Id);
        }
Esempio n. 2
0
        public async Task <string> Create(
            string ownerId,
            string contextResourceId,
            TagCreateData createData,
            Permission callerRights,
            IDictionary <RightType, Permission> collectionCallerRights)
        {
            var tagId = await Create(createData);

            await _userRightStore.CreateRights(
                ownerId,
                tagId,
                RightType.Tag.MakeCreateRights(callerRights, collectionCallerRights),
                new InheritForm
            {
                Type           = RightType.RootTagCollection,
                ResourceId     = contextResourceId,
                InheritedTypes = new List <RightType>
                {
                    RightType.Tag
                }
            });

            return(tagId);
        }