public async Task <UpdateCityPayload> UpdateCityAsync(UpdateCityInput input, [ScopedService] GeoDbContext context) { var city = await context.Cities.FindAsync(input.Id); city.Name = input.Name; await context.SaveChangesAsync(); return(new UpdateCityPayload(city)); }
public async Task <AddCityPayload> AddCityAsync(AddCityInput input, [ScopedService] GeoDbContext context) { var city = new Domain.City { Name = input.Name, CountryId = input.CountryId }; context.Cities.Add(city); await context.SaveChangesAsync(); return(new AddCityPayload(city)); }
public AuthenticationPayload Login(LoginUserInput input, [ScopedService] GeoDbContext context) { var user = context.Users .Where(i => i.Email.ToLower() == input.Email.ToLower()) .SingleOrDefault(); if (user == null) { return(new AuthenticationPayload(null, "User with this email address doesn't exists")); } var hash = HashHelper.GenerateHash(user.Salt, input.Password); if (hash != user.Hash) { return(new AuthenticationPayload(null, "Wrong password")); } return(GenerateAuthenticationResultForUser(user)); }
public async Task <AddCountryPayload> AddCountryAsync( AddCountryInput input, [ScopedService] GeoDbContext context, [Service] ITopicEventSender eventSender, CancellationToken cancellationToken ) { var country = new Domain.Country { Name = input.Name, Alpha2Code = input.Alpha2Code }; context.Countries.Add(country); await context.SaveChangesAsync(cancellationToken); await eventSender.SendAsync(nameof(CountrySubscriptions.OnCountryAdded), country, cancellationToken); return(new AddCountryPayload(country)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GeoDbContext context) { context.Database.Migrate(); _ = context.SeedAsync(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseOpenApi(); app.UseSwaggerUi3(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public IQueryable <Domain.City> GetCity([ScopedService] GeoDbContext context) => context.Cities;
public GeoMessagesController(GeoDbContext context, SignInManager <MyUser> signInManager) { _context = context; _signInManager = signInManager; }
public BaseRepository() { this.context = new GeoDbContext(); this.dataSet = this.context.Set <TEntity>(); }
public Country GetCountry(City city, [ScopedService] GeoDbContext context) { return(context.Countries.SingleOrDefault(i => i.Id == city.CountryId)); }
public CountryController(GeoDbContext context) { _context = context; }
public IQueryable <Domain.Country> GetCountry([ScopedService] GeoDbContext context) => context.Countries;
public async Task <ResponseMessagePayload> DeleteCountryAsync(DeleteCountryInput input, [ScopedService] GeoDbContext context) { var country = await context.Countries.FindAsync(input.Id); if (country == null) { return(new ResponseMessagePayload("Country not found")); } context.Countries.Remove(country); await context.SaveChangesAsync(); return(new ResponseMessagePayload("Country deleted")); }
public async Task <UpdateCountryPayload> UpdateCountryAsync(UpdateCountryInput input, [ScopedService] GeoDbContext context) { var country = await context.Countries.FindAsync(input.Id); country.Name = input.Name; country.Alpha2Code = input.Alpha2Code; country.Alpha3Code = input.Alpha3Code; await context.SaveChangesAsync(); return(new UpdateCountryPayload(country)); }
public async Task <AuthenticationPayload> RegisterAsync(RegisterUserInput input, [ScopedService] GeoDbContext context) { var existingUser = context.Users .Where(i => i.Email.ToLower() == input.Email.ToLower()) .SingleOrDefault(); if (existingUser != null) { return(new AuthenticationPayload(null, "User with this email address already exists")); } var salt = HashHelper.GenerateSalt(); var newUser = new User { Email = input.Email, Salt = salt, Hash = HashHelper.GenerateHash(salt, input.Password) }; var createdUser = await context.Users.AddAsync(newUser); await context.SaveChangesAsync(); return(GenerateAuthenticationResultForUser(newUser)); }
public IQueryable <Domain.City> GetCity(Domain.Country country, [ScopedService] GeoDbContext context) { return(context.Cities.Where(i => i.CountryId == country.Id)); }
public Handler(GeoDbContext geoDbContext) { _geoDbContext = geoDbContext; }
public GeoController(GeoDbContext context, UserManager <MyUser> userManager) { _context = context; _userManager = userManager; }
public GeoController(GeoDbContext context) { _context = context; }