Get up to 50 % extra points for free! More info
This week up to 80% off on C# .NET courses. More info

Lesson 14 - E-shop in ASP.NET Core MVC - Product reviews

In the previous lesson, E-shop in ASP.NET Core MVC - Product detail, we created the product detail page. In today's ASP.NET Core tutorial, we're going to add an option to rate individual products by users. It'll be possible to add one review per product by authenticated users. This new functionality will cause changes across the whole application layers, as we'll see in a moment. As always, let's have a look at the introductory motivational image:

Add product review form in ASP.NET Core MVC e-shop

Data layer

Entity model modifications

Let's add a new Review entity for storing reviews to the data project, it'll have relations to a product and a user. In addition to a primary key and foreign keys to these tables, we'll also store an integer value of the product rating (in the range of 1 - 5), the review content (2048 characters at most) and the date and time when the review was added. We'll create the reviews again just by specifying the virtual relationships to the given entities:

public class Review
    [DatabaseGenerated(DatabaseGeneratedOption.Identity), Key()]
    public int ReviewId { get; set; }

    [StringLength(2048, MinimumLength = 2, ErrorMessage = "The minimal length is 2 characters, maximum length is 2048 characters")]
    public string Content { get; set; }
    public string UserId { get; set; }
    public int ProductId { get; set; }
    public int Rating { get; set; }
    public DateTime Sent { get; set; }

    public virtual Product Product { get; set; }
    public virtual ApplicationUser User { get; set; }

We'll make minor changes to the existing Product and User entities as well. We'll add a virtual


...End of the preview...
Continue further

You will gain knowledge worth hundreds of thousands for a few crowns

You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.

Limited offer: Learn all knowledge and save money

Buy all currently available lessons with exercise submitting and other features for an exclusive price $70.38
Current account balance $0
By buying this exclusive package, you'll have access to all 34 lessons in this course including exercise submitting while saving $18.72. This is a time limited offer for all lessons in this course. Buy it now and gain a limited 21% discount.

Before buying this article, you have to buy the previous one

This article is licensed: Premium no-reselling II, by buying this article, you agree with the terms of use.

Commercial article (licence no-reselling)

Commercial article (licence no-reselling)

This article is based on many years of experience in the IT field, and describes how to develop a professional commercial product or parts, that can be directly used to generate profit or to get as a gate into the industry.

This knowledge is only for the members of our community who are working their way up to become IT professionals. Therefore, this knowledge is only available in exchange for credits. You can use the source code from this article for one commercial project. However, you will not be able to resell it. Simply put, you can't buy our article once and then sell our code multiple times. If you need to use this code a bit more extensively, we are ready to discuss Commercial licence options with you. You can find more info on this in the following article Licence.

Are you ready to become a professional? All you have to do is click here!.

Article description

Requested article covers this content:

In this tutorial, we'll add a new entity for product reviews including relations. We'll prepare a repository, a manager in the business layer, and views.

You gain credits by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.

Article has been written for you by Martin Petrovaj