public MembershipController(ILogger <MembershipController> logger, IOptions <QParaOptions> qpoptions,
                             QParaDb db, IWebHostEnvironment env) : base(logger, env)
 {
     this.options = qpoptions.Value;
     this.db      = db;
 }
Exemplo n.º 2
0
 public AuthController(IOptions <QParaOptions> options, QParaDb qparaDb, ILogger <AuthController> logger, IWebHostEnvironment env) : base(logger, env)
 {
     this.options = options.Value;
     this.db      = qparaDb;
     this.qpAuth  = GetAuthData();
 }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddNewtonsoftJson(options => {
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            var qpOptions = new QParaOptions();

            Configuration.GetSection("QParaOptions").Bind(qpOptions);
            log.Information($"Authentication idle timeout is {qpOptions.AuthenticationIdleTimeout} minutes");
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
                       options =>
            {
                options.ExpireTimeSpan    = TimeSpan.FromMinutes(qpOptions.AuthenticationIdleTimeout);
                options.LoginPath         = new PathString("/auth/login");
                options.AccessDeniedPath  = new PathString("/auth/denied");
                options.SlidingExpiration = true;
                options.Events            = new CookieAuthenticationEvents
                {
                    OnRedirectToLogin = ctx =>
                    {
                        if (ctx.Request.Path.StartsWithSegments("/membership") &&
                            ctx.Response.StatusCode == (int)HttpStatusCode.OK)
                        {
                            ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                        }
                        else
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                        return(Task.FromResult(0));
                    }
                };
            });
            services.AddOptions();
            services.Configure <QParaOptions>(Configuration.GetSection("QParaOptions"));

            services.Configure <QParaDbOptions>(Configuration.GetSection("QParaDbOptions"));
            var cs = environment.LocaliseConnectionString(Configuration.GetConnectionString("QParaDb"));

            services.AddDbContext <QParaDb>(options =>
            {
                try
                {
                    options.UseSqlServer(cs, sqlServerOptions =>
                    {
                        if (environment.IsDevelopment())
                        {
                            sqlServerOptions.CommandTimeout(60 * 3);
                        }
                    })
                    .EnableDetailedErrors()
                    .EnableSensitiveDataLogging()
                    .UseLazyLoadingProxies();
                }
                catch (Exception xe)
                {
                    log.Error(xe);
                    throw;
                }
            });
        }
Exemplo n.º 4
0
 public bool GetIsPaid(QParaOptions options)
 {
     return(this.Payments.Where(x => x.SubscriptionYear == options.GetCurrentSubscriptionYear())
            .Any(x => x.IsPaid));
 }
Exemplo n.º 5
0
        private void UpdatePaymentStatus(IIncludableQueryable <Member, ICollection <Change> > members, QParaOptions options, ILogger log)
        {
            this.ChangeTracker.AutoDetectChangesEnabled = false;
            var selectedMembers = members
                                  .Where(x => x.SubscriptionPeriod != SubscriptionPeriod.Life &&
                                         (x.SubscriptionType == SubscriptionType.Standard || x.SubscriptionType == SubscriptionType.Concession))
            ;
            var notSelectedMembers = members.Except(selectedMembers).Where(x => !x.GetIsPaid(options) /*!x.IsPaid*/);

            foreach (var m in notSelectedMembers.ToArray())
            {
                if (m.AmountDue != 0 || m.AmountReceived != 0)
                {
                    m.AmountDue = m.AmountReceived = 0;
                    log.Information($"{m.FirstName} {m.LastName} due and received amounts reset (to 0)");
                    //SaveChanges();
                }
            }
            var subscriptionYear = options.GetSubscriptionYear(DateTimeOffset.UtcNow);

            foreach (var m in selectedMembers.ToArray())
            {
                m.UpdatePaymentRecords(options, true);
                //SaveChanges();
            }
            ChangeTracker.DetectChanges();
            SaveChanges();
            this.ChangeTracker.AutoDetectChangesEnabled = true;
        }
Exemplo n.º 6
0
        public void RunV2DataConversion(int newMigrationCount, QParaDbOptions qpDbOptions, QParaOptions qpOptions, ILogger log)
        {
            //if (qpDbOptions.DisableDataConversion)
            //{
            //    log.Information($"DataConversion is disabled");
            //}
            //else
            //{
            log.Information($"V2 DataConversion running with {newMigrationCount} new migrations");
            var members = this.Members
                          .Include(x => x.Payments).ThenInclude(x => x.PaymentNotes).ThenInclude(x => x.Note)
                          .Include(x => x.MemberNotes).ThenInclude(x => x.Note)
                          .Include(x => x.Changes)
            ;

            RemoveExtraneousMembers(members, log);
            log.Information($"V2 DataConversion: extraneous members removed");
            ConvertPaymentsToSubscriptionYears(members, log);
            log.Information($"V2 DataConversion: payments converted to subscriptions years");

            if (qpDbOptions.ReloadMembers)
            {
                this.ChangeTracker.AutoDetectChangesEnabled = false;
                using (new TimedAction(t => log.Information($"member reload complete = {t.ToString("c")}")))
                {
                    foreach (var m in members)
                    {
                        this.Entry(m).Reload();
                    }
                }
                this.ChangeTracker.AutoDetectChangesEnabled = true;
            }
            UpdatePaymentStatus(members, qpOptions, log);
            log.Information($"V2 DataConversion: payment status for all members updated");
            if (qpDbOptions.AddMissingJoinedOnDates)
            {
                AddMissingJoinedOnDates(members, log);
                log.Information($"V2 DataConversion: joined on dates added where possible");
            }
            if (qpDbOptions.SplitMultipleMemberships)
            {
                //SplitMultipleMemberships(members, log);
            }
            log.Information($"V2 DataConversion finished");
            //}
        }