예제 #1
0
        /// <inheritdoc />
        public IConsent RegisterConsent(string source, string context, string action, ConsentState state, string comment = null)
        {
            // prevent stupid states
            var v = 0;

            if ((state & ConsentState.Pending) > 0)
            {
                v++;
            }
            if ((state & ConsentState.Granted) > 0)
            {
                v++;
            }
            if ((state & ConsentState.Revoked) > 0)
            {
                v++;
            }
            if (v != 1)
            {
                throw new ArgumentException("Invalid state.", nameof(state));
            }

            var consent = new Consent
            {
                Current    = true,
                Source     = source,
                Context    = context,
                Action     = action,
                CreateDate = DateTime.Now,
                State      = state,
                Comment    = comment
            };

            using (var scope = ScopeProvider.CreateScope())
            {
                _consentRepository.ClearCurrent(source, context, action);
                _consentRepository.Save(consent);
                scope.Complete();
            }

            return(consent);
        }
예제 #2
0
        /// <inheritdoc />
        public IConsent RegisterConsent(string source, string context, string action, ConsentState state, string comment = null)
        {
            // prevent stupid states
            var v = 0;

            if ((state & ConsentState.Pending) > 0)
            {
                v++;
            }
            if ((state & ConsentState.Granted) > 0)
            {
                v++;
            }
            if ((state & ConsentState.Revoked) > 0)
            {
                v++;
            }
            if (v != 1)
            {
                throw new ArgumentException("Invalid state.", nameof(state));
            }

            var consent = new Consent
            {
                Current    = true,
                Source     = source,
                Context    = context,
                Action     = action,
                CreateDate = DateTime.Now,
                State      = state,
                Comment    = comment
            };

            using (var uow = UowProvider.GetUnitOfWork())
            {
                var repository = RepositoryFactory.CreateConsentRepository(uow);
                repository.ClearCurrent(source, context, action);
                repository.AddOrUpdate(consent);
                uow.Commit();
            }

            return(consent);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RegisterConsentRequest"/> class.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="id">Extension id.</param>
 /// <param name="state">Sets the consent state of an extension.</param>
 RegisterConsentRequest(ExchangeService service, String id, ConsentState state)
     : super(service)
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RegisterConsentRequest"/> class.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="id">Extension id.</param>
 /// <param name="state">Sets the consent state of an extension.</param>
 internal RegisterConsentRequest(ExchangeService service, string id, ConsentState state)
     : base(service)
 {
     this.Id           = id;
     this.ConsentState = state;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RegisterConsentRequest"/> class.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="id">Extension id.</param>
 /// <param name="state">Sets the consent state of an extension.</param>
 internal RegisterConsentRequest(ExchangeService service, string id, ConsentState state)
     : base(service)
 {
     this.Id = id;
     this.ConsentState = state;
 }