0% found this document useful (0 votes)
34 views3 pages

001 Updating-To - Net-7

The document provides instructions for updating an API project to .NET 7. It involves: 1. Updating the TargetFramework and packages in the API.csproj file 2. Updating SwaggerUI configuration to persist authorization tokens 3. Adding validation to an Order property and updating OrderDate to use UTC 4. Creating a migration for the updated Order type 5. Dropping and recreating the database, then running the API 6. Checking for required Stripe API updates 7. Testing functionality in Swagger

Uploaded by

saralaraveli123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

001 Updating-To - Net-7

The document provides instructions for updating an API project to .NET 7. It involves: 1. Updating the TargetFramework and packages in the API.csproj file 2. Updating SwaggerUI configuration to persist authorization tokens 3. Adding validation to an Order property and updating OrderDate to use UTC 4. Creating a migration for the updated Order type 5. Dropping and recreating the database, then running the API 6. Checking for required Stripe API updates 7. Testing functionality in Swagger

Uploaded by

saralaraveli123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Updating to .

Net 7
1. Update the API.csproj

Update the TargetFramework to net7.0 and add the ImplicitUsings tag as well as the Nullable but
set to disabled in the API.csproj

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>e03e58b7-54a5-4902-a8df-e5e9a2b419fe</UserSecretsId>
</PropertyGroup>

2. Update the other packages in the API.csproj to the latest versions. This is how it looks at the
end of the course:

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>e03e58b7-54a5-4902-a8df-e5e9a2b419fe</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="CloudinaryDotNet" Version="1.20.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.1" />
<PackageReference Include="Stripe.net" Version="41.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>

3. Update the SwaggerUI middleware to persist the token we use as this configuration will save
the bearer token into localStorage:

if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.ConfigObject.AdditionalItems.Add("persistAuthorization", "true");

Updating to .Net 7 1
});
}

4. Update 2 properties in the Order.cs and add the Required tag to the ShippingAddress property
to avoid a warning we will receive when using EF 7 and owned entities, and set the OrderDate
to use DateTime.UtcNow instead of DateTime.Now which is required for the latest versions of
Postgres

using System.ComponentModel.DataAnnotations;

namespace API.Entities.OrderAggregate
{
public class Order
{
public int Id { get; set; }
public string BuyerId { get; set; }

[Required]
public ShippingAddress ShippingAddress { get; set; }
public DateTime OrderDate { get; set; } = DateTime.Now;
public List<OrderItem> OrderItems { get; set; }
public long Subtotal { get; set; }
public long DeliveryFee { get; set; }
public OrderStatus OrderStatus { get; set; } = OrderStatus.Pending;
public string PaymentIntentId { get; set; }

public long GetTotal()


{
return Subtotal + DeliveryFee;
}
}
}

5. Create a new migration that accommodates this type.

dotnet ef migrations add OrderUpdated

6. Drop the Database and start the API server.

dotnet ef database drop


dotnet run

7. If you have got to the stage of using Stripe then check to see if you need to upgrade your
version of the API in Stripe.net

Updating to .Net 7 2
If there is an upgrade available then choose the option to do this if you have updated the
Stripe.Net nuget package in your app.

8. Test the app functionality in Swagger.

Updating to .Net 7 3

You might also like