Skip to content

Instantly share code, notes, and snippets.

View gmartinezsan's full-sized avatar

Gabriela Martinez gmartinezsan

View GitHub Profile
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseAuthentication();
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
services.AddDbContext<BooksCatalogDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
else
{
services.AddDbContext<BooksCatalogDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("AzureConnection")));
}
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=HOST\\SQLEXPRESS;Initial Catalog=DbBooksCat;User ID=user;Password=YourPaasowrd;",
"AzureConnection": "Server=tcp:sqlserver.database.windows.net,1433;Initial Catalog=booksdb;Persist Security Info=False;User ID=admin;Password=YourPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug"
using System;
using BooksWebApi.Data;
using BooksWebApi.Entities;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace BooksWebApi
using BooksWebApi.Entities;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BooksWebApi.Data
{
public static class DataInitializer
using System;
using System.Threading.Tasks;
using BooksWebApi.Data;
using BooksWebApi.Entities;
using BooksWebApi.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace BooksWebApi.Controllers
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using BooksWebApi.Entities;
using BooksWebApi.Models;
using BooksWebApi.Repository;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using BooksWebApi.Entities;
using AutoMapper;
namespace BooksWebApi.Models
{
public class CategoryMappingProfile : Profile
{
public CategoryMappingProfile()
{
CreateMap<Category, CategoryModel>().ForMember(a => a.Books, opt => opt.ResolveUsing(c => c.Books))
using AutoMapper;
using BooksWebApi.Entities;
namespace BooksWebApi.Models
{
public class BookMappingProfile : Profile
{
public BookMappingProfile()
{
CreateMap<Book, BookModel>()
using System;
namespace BooksWebApi.Models
{
public class BookWithoutCategoryModel
{
public string Name { get; set; }
public string AuthorName { get; set; }
public int Edition { get; set; }
public DateTime PublicationDate { get; set; }