Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet 8 updates #14

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ContosoPizza/ContosoPizza.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.*-*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.*-*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.*-*" />
</ItemGroup>

</Project>
15 changes: 7 additions & 8 deletions ContosoPizza/Data/PizzaContext.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Microsoft.EntityFrameworkCore;

namespace ContosoPizza.Data
namespace ContosoPizza.Data;

public class PizzaContext : DbContext
{
public class PizzaContext : DbContext
public PizzaContext(DbContextOptions<PizzaContext> options)
: base(options)
{
public PizzaContext(DbContextOptions<PizzaContext> options)
: base(options)
{
}
public DbSet<ContosoPizza.Models.Pizza>? Pizzas { get; set; }
}
}
public DbSet<ContosoPizza.Models.Pizza>? Pizzas { get; set; }
}
34 changes: 16 additions & 18 deletions ContosoPizza/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
23 changes: 11 additions & 12 deletions ContosoPizza/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<IndexModel> _logger;
private readonly ILogger<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}

public void OnGet()
{
public void OnGet()
{

}
}
}
}
23 changes: 11 additions & 12 deletions ContosoPizza/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<PrivacyModel> _logger;
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}
public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
public void OnGet()
{
}
}
}
61 changes: 30 additions & 31 deletions ContosoPizza/Services/PizzaService.cs
Original file line number Diff line number Diff line change
@@ -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<Pizza> GetPizzas()
{
if(_context.Pizzas != null)
{
_context = context;
return _context.Pizzas.ToList();
}

public IList<Pizza> GetPizzas()
return new List<Pizza>();
}

public void AddPizza(Pizza pizza)
{
if (_context.Pizzas != null)
{
if(_context.Pizzas != null)
{
return _context.Pizzas.ToList();
}
return new List<Pizza>();
_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();
}
}
}
}
}
}
}