ASP.NET Core MVC CRUD - Shop management using Entity framework core, SQL Server |project series #16
Adding Store Name to Products Page
In this section, the speaker explains how to add the name of a store to the products page so that users can easily identify which store they are viewing.
Adding Store Name to Products Page
- To display the name of the store on the products page, we need to go to the product controller and use a view bag.
- We can integrate the action with the view through that feedback selected store.
- We need to pull the name of the store from the backup by fetching it from the service layer.
- We need to implement our own method inside the service layer since we don't have that functionality available in the generic repository.
Implementing Store Service
In this section, we learn how to implement a specific method inside a service layer.
Implementing Store Service
- We need a reference for this course repository here previously injected posting without assigning reference passed back to base.
- Due to that reason, we need to add a reference for I repost free in-store service and assign it as repository for stores plus key is equal to repository.
- We want these entity which has ID and equals store ID foreign next we don't want return whole object instead select specific value which is name of store.
- If an invalid store ID is passed, it will return null. In that case, we can return "store and name".
Adding Store Name to Controller
In this section, the speaker explains how to add a specific method inside a service and utilize it in the actions.
Injecting Store Service
- The store service is injected into the product controller.
- The
getStoreNameByIDmethod is used to get the name of a particular store by passing its ID as an argument.
Assigning Value to View
- The value returned by
getStoreNameByIDis assigned to view back.
- The view is refreshed so that the store name appears on top of the page.
Displaying Product Text at Top of Page
In this section, the speaker demonstrates how to display product text at the top of a page when a user clicks on a particular store or its products.
Displaying Products for Specific Stores
- When a user clicks on a specific store, its products are displayed at the top of the page.
- Similarly, when a user clicks on specific products, their text appears at the top of the page.
Conclusion
The video ends with an invitation for viewers to ask questions or queries in the comments.