In an Model-View-Controller (MVC) design pattern, What goes where? What code goes to model and to controller?
I know (do I?) that business logic should be define in a model, but a lot of example I find on the internet only use the model to define the data. Take Microsoft's example of model for instance, it only writes it this way:
using System.ComponentModel.DataAnnotations;
namespace MvcMovie.Models
{
public class Movie
{
public int Id { get; set; }
public string? Title { get; set; }
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
public string? Genre { get; set; }
public decimal Price { get; set; }
}
}
Then defines the business logic on a controller...
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}
var movie = await _context.Movie
.FirstOrDefaultAsync(m => m.Id == id);
if (movie == null)
{
return NotFound();
}
return View(movie);
}
Meanwhile...
I worked with an MVC project with my friend before back when I'm still a student and on his code, all the business logic such as interacting with the database are done in the model and not on the controller.
I'm working on my personal project right now and I'm writing my database interaction on my model. Am I right?
So,... What really goes where???