예제 #1
0
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId             = string.Empty;
            string clientSecret         = string.Empty;
            string symmetricKeyAsBase64 = string.Empty;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null)
            {
                context.SetError("invalid_clientId", "client_Id is not set");
                return(Task.FromResult <object>(null));
            }

            Models.Audience audience = AudiencesStore.FindAudience(context.ClientId);

            if (audience == null)
            {
                context.SetError("invalid_clientId", string.Format("Invalid client_id '{0}'", context.ClientId));
                return(Task.FromResult <object>(null));
            }

            context.Validated();
            return(Task.FromResult <object>(null));
        }
예제 #2
0
        public static int Save(Models.Audience audience)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(audience).State = audience.AudienceId.Equals(0) ? EntityState.Added : EntityState.Modified;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
예제 #3
0
        public static object Delete(Models.Audience audience)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(audience).State = audience.AudienceId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
예제 #4
0
        /// <inheritdoc />
        public async Task <Audience> GetByFeatureId(Guid featureId, CancellationToken cancellationToken = default)
        {
            if (featureId == Guid.Empty)
            {
                throw new ArgumentException("Invalid Feature Id");
            }

            Models.Audience audience = await _dbContext.Audiences
                                       .SingleOrDefaultAsync(a => a.FeatureId == featureId, cancellationToken)
                                       .ConfigureAwait(false);

            return(audience == null ? null : _iMapper.Map <Models.Audience, Audience>(audience));
        }
예제 #5
0
 public static Models.Audience GetSchoolAudience(string school, bool createIfMissing)
 {
     using (var db = new Context.SqlContext())
     {
         if (string.IsNullOrEmpty(school))
         {
             return(null);
         }
         var n = db.Audience.FirstOrDefault <Models.Audience>(v => v.SchoolAudienceValue.Equals(school) & v.GradeLevelAudienceValue.Equals(null) & v.TeacherAudienceValue.Equals(null));
         if ((n == null) && (createIfMissing))
         {
             n = new Models.Audience();
             n.SchoolAudienceValue = school;
             n.AudienceName        = school;
             n.Selectable          = true;
             Save(n);
         }
         return(n);
     }
 }