I am working on my first real MVC application, and I try to follow the general recommendations of OOP. I am reorganizing the simple business logic that I used in the controller in my domain model. I've been reading lately, and it seems pretty clear that I have to put the logic somewhere in the domain model entity class to avoid the anti-anomalous domain model anti-pattern.
The application will allow people to buy leasing for parking spaces. Rates are determined by the length of the seat and regardless of whether the client is a member of the business park.
So, I have entity classes in my domain model that look like this (simplified):
public class Customer { int ID { get; set; } string Name { get; set; } bool IsMember { get; set; } } public class ParkingSpace { int ID { get; set; } int Length { get; set; } } public class ParkingSpaceLease { int ID { get; set; } DateTime OpenDate { get; set; } DateTime CloseDate { get; set; } Customer Customer { get; set; } ParkingSpace ParkingSpace { get; set; } }
Edit: Just to clarify that LeaseQuote is not an essential class, because it is simply used to display cost breakdowns for prospective customers and is not saved anywhere.
public class LeaseQuote { int SubTotal { get; set; } int Discount { get; set; } int Total { get; set; } }
Now, as a function of the application, I need to be able to generate quotes for different combinations of customers and parking spaces. Quotation marks will usually be available outside the context of the actual rental creation, for example, when a customer calls to find out the price.
So what is the best way to do this? Does it make sense to create an instance of a new ParkingSpaceLease object inside the controller only to call the GetQuote method on it?
var lease = new ParkingSpaceLease(); var quote = lease.GetQuote(length: 168, isMember: true); return Json(quote);
Or should the LeaseQuote class use a method?
var leaseQuote = new LeaseQuote(); var quote = leaseQuote.GetQuote(length: 168, isMember: true); return Json(quote);
It feels weird when introducing logic into the ParkingSpaceLease class. I think that to create a new rental object I feel "difficult" when I know that I am not going to actually do anything with it, except for access to the GetQuote method, which seems like a separate service.
So where should the GetQuote method go and why should it go there?