From 2320104a5776a979d65539286a0182874f4dc1e8 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Mon, 23 Oct 2023 12:36:02 -0400 Subject: [PATCH 1/3] updates --- ContosoPizza/ContosoPizza.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ContosoPizza/ContosoPizza.csproj b/ContosoPizza/ContosoPizza.csproj index 1c90330..5105200 100644 --- a/ContosoPizza/ContosoPizza.csproj +++ b/ContosoPizza/ContosoPizza.csproj @@ -7,12 +7,12 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 1f2fe2686a26a2769af0a0e305b3d71e9f339bec Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Mon, 23 Oct 2023 14:25:02 -0400 Subject: [PATCH 2/3] version bump --- ContosoPizza/ContosoPizza.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ContosoPizza/ContosoPizza.csproj b/ContosoPizza/ContosoPizza.csproj index 5105200..05636d9 100644 --- a/ContosoPizza/ContosoPizza.csproj +++ b/ContosoPizza/ContosoPizza.csproj @@ -1,18 +1,18 @@ - net7.0 + net8.0 enable enable - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 797a1795d69545f800e64b7aa9283b843be1aafd Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Mon, 23 Oct 2023 14:36:11 -0400 Subject: [PATCH 3/3] fix namespaces --- ContosoPizza/Data/PizzaContext.cs | 15 +++---- ContosoPizza/Pages/Error.cshtml.cs | 34 +++++++-------- ContosoPizza/Pages/Index.cshtml.cs | 23 +++++----- ContosoPizza/Pages/Privacy.cshtml.cs | 23 +++++----- ContosoPizza/Services/PizzaService.cs | 61 +++++++++++++-------------- 5 files changed, 75 insertions(+), 81 deletions(-) diff --git a/ContosoPizza/Data/PizzaContext.cs b/ContosoPizza/Data/PizzaContext.cs index 9a9071b..976ff1d 100644 --- a/ContosoPizza/Data/PizzaContext.cs +++ b/ContosoPizza/Data/PizzaContext.cs @@ -1,13 +1,12 @@ using Microsoft.EntityFrameworkCore; -namespace ContosoPizza.Data +namespace ContosoPizza.Data; + +public class PizzaContext : DbContext { - public class PizzaContext : DbContext + public PizzaContext(DbContextOptions options) + : base(options) { - public PizzaContext(DbContextOptions options) - : base(options) - { - } - public DbSet? Pizzas { get; set; } } -} + public DbSet? Pizzas { get; set; } +} \ No newline at end of file diff --git a/ContosoPizza/Pages/Error.cshtml.cs b/ContosoPizza/Pages/Error.cshtml.cs index 7db284d..b402a30 100644 --- a/ContosoPizza/Pages/Error.cshtml.cs +++ b/ContosoPizza/Pages/Error.cshtml.cs @@ -1,28 +1,26 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; - using System.Diagnostics; -namespace ContosoPizza.Pages +namespace ContosoPizza.Pages; + +[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] +[IgnoreAntiforgeryToken] +public class ErrorModel : PageModel { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string? RequestId { get; set; } + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - private readonly ILogger _logger; + private readonly ILogger _logger; - public ErrorModel(ILogger logger) - { - _logger = logger; - } + public ErrorModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } -} \ No newline at end of file +} diff --git a/ContosoPizza/Pages/Index.cshtml.cs b/ContosoPizza/Pages/Index.cshtml.cs index d3f2011..0e597bd 100644 --- a/ContosoPizza/Pages/Index.cshtml.cs +++ b/ContosoPizza/Pages/Index.cshtml.cs @@ -1,20 +1,19 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace ContosoPizza.Pages +namespace ContosoPizza.Pages; + +public class IndexModel : PageModel { - public class IndexModel : PageModel - { - private readonly ILogger _logger; + private readonly ILogger _logger; - public IndexModel(ILogger logger) - { - _logger = logger; - } + public IndexModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { + public void OnGet() + { - } } -} \ No newline at end of file +} diff --git a/ContosoPizza/Pages/Privacy.cshtml.cs b/ContosoPizza/Pages/Privacy.cshtml.cs index 329bacd..88ca34d 100644 --- a/ContosoPizza/Pages/Privacy.cshtml.cs +++ b/ContosoPizza/Pages/Privacy.cshtml.cs @@ -1,19 +1,18 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace ContosoPizza.Pages +namespace ContosoPizza.Pages; + +public class PrivacyModel : PageModel { - public class PrivacyModel : PageModel - { - private readonly ILogger _logger; + private readonly ILogger _logger; - public PrivacyModel(ILogger logger) - { - _logger = logger; - } + public PrivacyModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { - } + public void OnGet() + { } -} \ No newline at end of file +} diff --git a/ContosoPizza/Services/PizzaService.cs b/ContosoPizza/Services/PizzaService.cs index 7aee8cf..d982c6d 100644 --- a/ContosoPizza/Services/PizzaService.cs +++ b/ContosoPizza/Services/PizzaService.cs @@ -1,46 +1,45 @@ using ContosoPizza.Data; using ContosoPizza.Models; -namespace ContosoPizza.Services +namespace ContosoPizza.Services; + +public class PizzaService { - public class PizzaService - { - private readonly PizzaContext _context = default!; + private readonly PizzaContext _context = default!; - public PizzaService(PizzaContext context) + public PizzaService(PizzaContext context) + { + _context = context; + } + + public IList GetPizzas() + { + if(_context.Pizzas != null) { - _context = context; + return _context.Pizzas.ToList(); } - - public IList GetPizzas() + return new List(); + } + + public void AddPizza(Pizza pizza) + { + if (_context.Pizzas != null) { - if(_context.Pizzas != null) - { - return _context.Pizzas.ToList(); - } - return new List(); + _context.Pizzas.Add(pizza); + _context.SaveChanges(); } + } - public void AddPizza(Pizza pizza) + public void DeletePizza(int id) + { + if (_context.Pizzas != null) { - if (_context.Pizzas != null) + var pizza = _context.Pizzas.Find(id); + if (pizza != null) { - _context.Pizzas.Add(pizza); + _context.Pizzas.Remove(pizza); _context.SaveChanges(); } - } - - public void DeletePizza(int id) - { - if (_context.Pizzas != null) - { - var pizza = _context.Pizzas.Find(id); - if (pizza != null) - { - _context.Pizzas.Remove(pizza); - _context.SaveChanges(); - } - } - } - } + } + } }