Monthly Archives: April 2024

ORGANIZE VIEWS INTO COMPONENTS

ORGANIZE VIEWS INTO COMPONENTS CREATE CUSTOM HELPER TAGS Creating a component is important because then we can reuse that logic in the Views that make up the application. We will have created something that is testable in isolation, in fact as we will see we can create automated tests to prove that each of our components works. Let's see how to write the Tag Helper containing the rating star logic. There are conventions to follow, the component being named RatingTagHelper, in the View Razor the tag will be rating. When [...]

By |2024-04-01T04:29:37+00:00April 1, 2024|0 Comments

VALIDATE AND PERSIST DATA PART ONE

VALIDATE AND PERSIST DATA DESIGNING A TASK-BASED UI We are going to look at how data insertion, editing and deletion are accomplished. Let's start with the course entry form, and immediately we have to ask ourselves what data to ask the user for? If we present all the information to be entered at once, the user might be disoriented with all the amount of data to be entered, then we could break this amount of data into smaller Forms, so that the user enters the data that our application needs gradually. After the title is entered, [...]

By |2024-04-05T19:05:49+00:00April 5, 2024|0 Comments

VALIDATE AND PERSIST DATA PART TWO

VALIDATE AND PERSIST DATA DATA ENTRY WITH ADO.NET Thanks to model binding in the title entry form what the user types in is found in the CourseCreateInputModel class in the Create method of type HTTP POST of CoursesController. This is the code for ADO.NET Insert method. INSERT ENTITY WITH ENTITY FRAMEWORK CORE Again we are going to insert a course with the object model we are used to. The moment we want to add a row we use the Add(...) method of the DbContext creating a Course entity. However, the row is [...]

By |2024-04-07T06:14:06+00:00April 7, 2024|0 Comments

VALIDATE AND PERSIST DATA PART THREE

VALIDATE AND PERSIST DATA VIEW AND CUSTOMIZE VALIDATION ERRORS Validation is intended to be server-side, this is because the correctness of the data is verified not in the Browser but in the ASP.NET Core application. The problem with what we have implemented so far is that if even the validation is not successful, the user is not notified in any way. Microsoft has set up special TagHelpers to display validation errors. CLIENT-SIDE VALIDATION Server-side validation is essential and we should never, ever do without it. It must be [...]

By |2024-04-10T20:39:07+00:00April 10, 2024|0 Comments

DESIGN THE EDIT FUNCTION PART ONE

DESIGN THE DATA EDITING FUNCTIONALITY Let's go through a slide to see what we need to make the edit form. Let's start with the Input Model class. We keep responsibilities separate and avoid the temptation to use other classes. Our input model for editing will be CourseEditInputModel.cs We see a Data Annotation Display that is not for validation but only to display a label in the UI that will facilitate translations in multilingual sites. In the CourseEditInputModel.cs class in addition to the Data Annotation Display, there [...]

By |2024-04-13T06:16:35+00:00April 13, 2024|0 Comments

DESIGNING EDITING FUNCTIONALITY PART TWO

DESIGNING EDITING FUNCTIONALITY INSTALL A WYSIWYG EDITOR At the moment for the description we used a very normal Text Area. This may not work well because if the lecturer wanted to explain the contents of his course in full, he would not have the opportunity to do so. We will replace the header box with an editor, so being able to use subtitles, put bold characters etc. We will see that a WYSIWYG editor can also pose security risks. The Text Area will remain within the form; an editor is not meant to replace it, rather to supplement it. [...]

By |2024-04-16T14:47:45+00:00April 16, 2024|0 Comments

DESIGNING EDITING FUNCTIONALITY PART THREE

DESIGNING EDITING FUNCTIONALITY SAVE A FILE UPLOADED BY THE USER We will see how it is possible to save an 'image so that it is usable by all users of the application. To save the image, I created a new interface in the IImagePersister.cs infrastructure service. I'll show you the code. It returns a Task<string> because this infrastructure service knows where to persist the image and how to get to it. The class that implements the interface is called InsecureImagePersister.cs, and you will understand why it is insecure in a moment. The method will use a [...]

By |2024-04-17T20:22:00+00:00April 17, 2024|0 Comments

TECHNIQUES FOR WORKING WITH DATA PART ONE

During the Refactoring phase, we defined two new methods in the infrastructure service IDatabaseAccessor.cs which I show you with an image, but first I want to briefly explain what the topics of this post will be. We will talk about the problem of concurrency, that is, when two users try to edit the same information at the same time, and we will see that there are two approaches to dealing with this problem, pessimistic competition and optimistic competition. In this project we will use the second approach. The methods in question are QueryScalarAsync<T> and CommandAsync, these [...]

By |2024-04-23T04:04:15+00:00April 23, 2024|0 Comments

TECHNIQUES FOR WORKING WITH DATA PART TWO

TECHNIQUES FOR WORKING WITH DATA CREATE THE FIRST MIGRATIONS WITH EFCORE When we are asked to implement a new feature, the need to add new columns to the database often happens. We have seen that there are two approaches, the Database-First is to connect to the database and run the scripts necessary to add a new column in a table. Using the Code-First approach first you modify the application code then with the EFCore Migrations mechanism you make the changes to the database. Let's see how to create the first Migrations. [...]

By |2024-04-27T08:33:41+00:00April 27, 2024|0 Comments

AUTHENTICATION AND AUTHORIZATION PART ONE

ASP.NET CORE AUTHENTICATION AND AUTHORIZATION UNDERSTAND THE AUTHENTICATION AND AUTHORIZATION STEPS Authentication and authorization are crucial parts of most web applications, take lecture content as an example, it should not be shown to everyone, but only to a subset of users, namely those who have purchased the course. So, too, should the modification that should be the prerogative only of the person who created the course. In and start with authentication. Suppose we go to vote, so we go to the polling station. The poll worker does not let us vote right away, but first wants to make sure of [...]

By |2024-05-03T11:00:56+00:00April 28, 2024|0 Comments
Go to Top