Here is part of an ASP.NET MVC program, from https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/controller-methods-views?view=aspnetcore-3.1 :
A model class Movie:
public class Movie
{
public int Id { get; set; }
public string Title { get; set; }
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
[Column(TypeName = "decimal(18, 2)")]
public decimal Price { get; set; }
}
and a method from a controller class MoviesController is:
// GET: Movies/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var movie = await _context.Movie.FindAsync(id);
if (movie == null)
{
return NotFound();
}
return View(movie);
}
If I want to write an ASP.NET MVC program into three layers: presentation, business logic and data access layers,
Since presentation layer is responsible to provides output to users and interact with users, should both view and controller belong to the presentation layer?
Should the business layer be implemented by the model
Movie?"The Model in an MVC application represents the state of the application and any business logic or operations that should be performed by it" seems to say so.
Does the business layer need to be implemented as some method, whereas the model doesn't have any method? (I guess the model class is used as an entity class by the Entity Framework. Does EF require every entity class have no method?)
In the method of the controller,
_context.Movie.FindAsync(id)is using Entity Framework (ORM) to make a query. So does the controller also implement the data access layer, besides implementing part of the presentation layer?How shall I separate presentation, business logic and data access layers?
Thanks.