Пример #1
0
        public async Task <bool> Set(IWorkContext context, UserRoleDoc userRole, string eTag = null)
        {
            if (eTag.IsEmpty() && _cache.TryGetValue(out HeaderDoc <UserRoleDoc> value))
            {
                eTag = value?.ETag;
            }

            _cache.Clear();
            return(await _roleRepository.Set(context, userRole, eTag));
        }
Пример #2
0
        public async Task <bool> Set(IWorkContext context, UserRoleDoc userRole, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotNull(nameof(userRole), userRole);
            context = context.WithTag(_tag);

            var envelope = new HeaderDoc <UserRoleDoc>(userRole);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) == userRole.RoleId);

            if (eTag.IsEmpty())
            {
                return(await _collection.Upsert(context, query.ToDocument(), envelope).ConfigureAwait(false));
            }

            query += (new Field(nameof(HeaderDoc <UserRoleDoc> .ETag)) == eTag);
            return(await _collection.Update(context, query.ToDocument(), envelope).ConfigureAwait(false));
        }