Easily create a friendly News Agency UI, using .Net Core MVC

Patroclos Lemoniatis
4 min readApr 18, 2023

--

image from pixabay by TheAngryTeddy

In this blog,

we will cover how easy it is to create a sample web application User interface using .NET MVC, using NHibernate, SQLite, Model AutoMapper and Razor pages.

What is MVC?

MVC, which stands for Model-View-Controller, is a software development architecture pattern used to structure and organize code in web applications. It separates an application’s concerns into three components: the model, view, and controller.

Why use .Net Core?

There are several reasons why you might consider using .NET Core

  1. Cross-platform support: .NET Core runs on multiple operating systems, including Windows, Linux, and macOS
  2. Open-source and community-driven
  3. Integration with other Microsoft technologies: .NET Core integrates well with other Microsoft technologies such as Azure, Visual Studio, and SQL Server, making it easy to build, deploy, and manage applications within the Microsoft ecosystem.

Razor Pages

Razor Pages allows developers to build server-side web pages using the Razor syntax, which is a combination of HTML markup and server-side code. Each web page is represented by a -page model- class that contains the code needed to generate the HTML markup. The page model class is defined in a C# code file and is associated with a Razor view file that contains the HTML markup and Razor syntax for the page.

NHibernate

NHibernate is an open-source object-relational mapping (ORM) framework for the .NET platform. It provides a bridge between the object-oriented programming paradigm of .NET and the relational database world.

It provides a wide range of features to help developers manage the persistence of data, including support for lazy loading, caching, and transaction management.

Some advantages of using NHibernate are:

  1. Abstraction of database details: NHibernate provides a high-level, object-oriented interface for working with database data.
  2. Increased productivity: NHibernate reduces the amount of boilerplate code required to manage database data, which can speed up development time.
  3. Improved maintainability: NHibernate provides a clear separation between the data access layer and the business logic layer of an application, which makes it easier to maintain and update the codebase over time.
  4. Support for multiple database platforms: NHibernate supports a wide range of database platforms, including Microsoft SQL Server, Oracle, MySQL, and PostgreSQL.

SQLite database

It is a lightweight and self-contained database engine that can be embedded into applications to store data in a local file. SQLite is open source and free to use, and it supports SQL (Structured Query Language) syntax for creating, querying, and managing data stored in the database.

SQLite is widely used in various types of software applications, such as desktop and mobile applications, web browsers, and operating systems. SQLite is also known for its reliability, stability, and scalability, which makes it an ideal choice for many software developers.

What is AutoMapper?

AutoMapper is a library that allows automatic mapping from one object to another, eliminating extra code to be written every time a mapper is required to map an entity to a DTO and vice-versa.

Lets see the UI example

Suppose a News Agency, needs to store, retrieve and edit new and existing articles.

The solution, therefore, is to create a Web Application with an Articles summary and detail page.

Summary Page: Display all the non deleted articles in a table format

Detail Page: Open a new page to edit a specific article or create a new article

This is the Read Mode where with the use of Razor syntax, the components are shown as Labels instead of TextBoxes.

When the Edit link is clicked, the Label components are replaced with TextBoxes.

Fell free to grab a copy of the source code and play !

--

--

Patroclos Lemoniatis
Patroclos Lemoniatis

No responses yet