Skip to content

Instantly share code, notes, and snippets.

Avatar

Felipe Gavilán gavilanch

  • República Dominicana
View GitHub Profile
View Program.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace ConsoleApp4
{
class Program
{
View example.html
<select class="form-control" @onchange="ChangeMessageFilter">
<option value="---" selected=@(Filter.Message == "---")>---</option>
<option value="Request" selected=@(Filter.Message == "Request")>Request</option>
<option value="Response" selected=@(Filter.Message == "Response")>Response</option>
</select>
View appsettings.json
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "CN=SUBJECT_NAME"
}
View appsettings.development.json
"IdentityServer": {
"Key": {
"Type": "Development"
}
}
View script-2012.sql
USE [master]
GO
/****** Object: Database [ValuesDB] Script Date: 16-Jul-20 10:45:22 PM ******/
CREATE DATABASE [ValuesDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'ValuesDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\ValuesDB.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'ValuesDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\ValuesDB_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
View PeliculasController.cs
peliculasQueryable = peliculasQueryable.OrderByDescending(x => x.VotosPelicula.Average(y => y.Voto));
View Startup.cs
services.AddDbContext<ApplicationDbContext>((serviceProvider, dbContextBuilder) =>
{
var connectionStringPlaceHolder = Configuration.GetConnectionString("PlaceHolderConnection");
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
var dbName = httpContextAccessor.HttpContext.Request.Headers["tenantId"].First();
var connectionString = connectionStringPlaceHolder.Replace("{dbName}", dbName);
dbContextBuilder.UseSqlServer(connectionString);
});
View appsettings.json
"ConnectionStrings": {
"PlaceHolderConnection": "Data Source=.;Initial Catalog={dbName};Integrated Security=True",
}
...
View startup.cs
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
));
View PeopleController.cs
[HttpGet("{id}")]
public async Task<ActionResult<Person>> Get(int id)
{
var person = await context.People.Include(x => x.MoviesActors).ThenInclude(x => x.Movie).FirstOrDefaultAsync(x => x.Id == id);
if (person == null) { return NotFound(); }
return person;
}