Skip to content

Instantly share code, notes, and snippets.

@PadreSVK
PadreSVK / AccountController.cs
Created December 16, 2019 04:58
Login controller and views
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using BL;
using DAL.Models.Identity;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
@PadreSVK
PadreSVK / script.js
Created December 15, 2019 21:15
Get data from server
document.cookie
const response = await fetch('https://localhost:5001/weather/GetAllCities', {method: "POST"});
const myJson = await response.json();
console.log(JSON.stringify(myJson));
fetch('https://localhost:5001/weather', {method: "POST"})
.then(response => response.json())
.then(json=> console.log(JSON.stringify(json)))
@PadreSVK
PadreSVK / DatabaseSeed.cs
Created December 15, 2019 18:19
Add seeds for Identity
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DAL.Models.Identity;
using Microsoft.AspNetCore.Identity;
namespace DAL
{
public class DatabaseSeed
{
@PadreSVK
PadreSVK / Startup.cs
Created December 15, 2019 18:11
Registration of identity infrastructure to IoC
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<OpenWeatherDbContext>()
.AddUserManager<UserManager>();
@PadreSVK
PadreSVK / UserRole.cs
Created December 15, 2019 17:41
User and Role wrapper around Identity
using Microsoft.AspNetCore.Identity;
namespace DAL.Models.Identity
{
public class Role : IdentityRole<int>
{
}
public class User : IdentityUser<int>
{
}
@PadreSVK
PadreSVK / generateMigrationScript.ps1
Created December 15, 2019 16:20
MIgration script pre CI
dotnet ef migrations script --project DAL --context OpenWeatherDbContext --startup-project OpenWeather --output $(build.artifactstagingdirectory)/db_migrations.sql --idempotent
using System;
using System.Threading;
using System.Threading.Tasks;
using BL;
using DAL.Models;
using DAL.Query.Abstraction;
using DAL.Query.AllCity;
using DAL.Repositories.Abstraction;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@PadreSVK
PadreSVK / IStatisticService.cs
Created December 14, 2019 22:22
statistic service interface
using System.Threading.Tasks;
namespace BL
{
public interface IStatisticService
{
Task<double> GetAveragePressureByCityAsync(int cityId);
Task<double> GetAverageTemperatureByCityAsync(int cityId);
}
}
@PadreSVK
PadreSVK / Startup.cs
Created December 14, 2019 21:59
Registrácia HTTP clienta
services.AddHttpClient<IOpenWeatherClient, OpenWeatherClient>(s =>
{
var options = new OpenWeatherHttpClientOptions();
Configuration.GetSection("OpenWeatherHttpClientOptions").Bind(options);
s.BaseAddress = new Uri(options.Url);
});
@PadreSVK
PadreSVK / OpenWeatherClient.cs
Created December 14, 2019 21:51
Http client for OpenWeatherAPI
using System.Threading.Tasks;
using BackgroundServices.Models;
using BackgroundServices.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace BackgroundServices.HttpClients
{
public interface IOpenWeatherClient