In my solution, I have two projects.
Project 1 (Core) Mapping SQL to DTO Using Dapper
Project 2 (WebUI - ASP.NET MVC 4) Here I use ViewModel for each view.
Controller Examples
[HttpGet] public ActionResult Edit(int id) {
ViewModel Examples
public class ProductFormModel : BaseViewModel, ICreateProductCommand { public int ProductId { get; set; } public int ProductGroupId { get; set; } public string ArtNo { get; set; } public bool IsDefault { get; set; } public string Description { get; set; } public string Specification { get; set; } public string Unit { get; set; } public string Account { get; set; } public decimal NetPrice { get; set; } public ProductFormModel(int productGroupId) { this.ProductGroupId = productGroupId; } public ProductFormModel(ProductDto dto) { this.ProductId = dto.ProductId; this.ProductGroupId = dto.ProductGroupId; this.ArtNo = dto.ArtNo; this.IsDefault = dto.IsDefault; this.Description = dto.Description; this.Specification = dto.Specification; this.Unit = dto.Unit; this.Account = dto.Account; this.NetPrice = dto.NetPrice; } public ProductFormModel() { } }
Explanation: I will get my DTOs in the controller using the service class in the project (Core). Then I create my ViewModel and pass the DTO to the constructor in the ViewModel. I can also use this view to add a new product, because my ViewModel can accept an empty constructor.
Does anyone have any experience with this. I wonder if in this way I will have problems in the future when the project becomes larger?
I know this has nothing to do with Dapper. But I still would like to find a good way to explain my decision.
source share