Exemple #1
0
 public CommandValidator(GoalzillaDbContext dbContext)
 {
     RuleFor(c => c.Body)
     .Cascade(CascadeMode.StopOnFirstFailure)
     .NotNull()
     .SetValidator(new EventModelValidator(dbContext));
 }
Exemple #2
0
 public RsvpModelValidator(GoalzillaDbContext dbContext)
 {
     RuleFor(rsvp => rsvp.AttendeeId)
     .Cascade(CascadeMode.StopOnFirstFailure)
     .NotNull()
     .MustAsync(async(attendeeId, ct) =>
                await dbContext.Users.AnyAsync(u => u.UserId == attendeeId, ct))
     .WithMessage((rsvp, attendeeId) => $"User with Id '{attendeeId}' not found");
 }
Exemple #3
0
        public EventModelValidator(GoalzillaDbContext dbContext)
        {
            RuleFor(e => e.Title)
            .NotEmpty()
            .Length(1, 128);

            RuleFor(e => e.CreatorId)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .NotNull()
            .MustAsync(async(creatorId, ct) =>
                       await dbContext.Users.AnyAsync(u => u.UserId == creatorId, ct))
            .WithMessage((@event, creatorId) => $"User with Id '{creatorId}' not found");
        }
Exemple #4
0
            public CommandValidator(GoalzillaDbContext dbContext)
            {
                RuleFor(c => c.Body)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotNull()
                .SetValidator(new RsvpModelValidator(dbContext));

                RuleFor(c => c.EventId)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotNull()
                .MustAsync(async(eventId, ct) =>
                           await dbContext.Events.AnyAsync(e => e.EventId == eventId, ct))
                .WithMessage((command, eventId) => $"Event with Id '{eventId}' not found");
            }
Exemple #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GoalzillaDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", $"{ApiName} V1");
            });
            app.UseMiddleware <ErrorHandlingMiddleware>();
            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

            // Apply new migrations to DB.
            ApplicationDbInitializer.ApplyMigrations(dbContext);
        }
Exemple #6
0
 public Handler(GoalzillaDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }
Exemple #7
0
 public Handler(GoalzillaDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _mapper    = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }