Blazor in Action by Chris Sainty

Blazor in Action by Chris Sainty

Author:Chris Sainty [Chris Sainty]
Language: eng
Format: epub
Publisher: Manning Publications
Published: 2022-06-19T00:00:00+00:00


6.4.3 Adding the edit trail feature

Before we start making any changes in the Client project to enable editing, we need to make some changes to the Shared project. There are a few jobs for us to do:

We must update the TrailDto class—specifically, to handle updating the trail image.

We need to update the folder structure so it mirrors the feature folder structure in the Client project.

We need to add two new requests for our edit functionality: EditTrailRequest and GetTrailRequest.

Let’s work through each of these items, starting at the top.

Updating the TrailDto class

When editing a trail, we will need to be able to display the trail’s current image, if it has one. We will also need to give the user the ability to remove the image, update it, or leave it unchanged. To enable these scenarios, we’ll update the class with two additional properties and a new enum, as shown in the following listing.

Listing 6.22 TrailDto.cs: Add new properties and ImageAction enum

public class TrailDto { // other properties omitted public string? Image { get; set; } ❶ public ImageAction ImageAction { get; set; } ❷ } public enum ImageAction ❸ { None, Add, Remove }

❶ Image holds the filename of an existing image.

❷ ImageAction allows us to set what operation to perform on the trail image when updating the trail.

❸ Contains the various operations that can be performed on an image

When we add the edit functionality to the Client project, we need to load the trail to edit from the API. At this point we need to know if the trail has an image. This is where the new Image property comes in. If there is an image, this will contain the filename of that image so we can display it to the user.

When the user is modifying a trail with an image, we need to know what operation, if any, we’re performing on that image. This is where the second new property and new enum come in. If they add or remove the image, we will record that intent using the ImageAction property. We can then reference this in our endpoint to understand what to do.

Updating the Shared project’s folder structure

To keep things organized, we want to make sure we keep the same feature folder structure throughout the solution. Based on our changes in the Client project, we need to add three new folders in the ManageTrails folder:

AddTrail



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.