Reporting Modeling in ASP NET MVC

Asked

Viewed 192 times

0

I have several reports in the company, and I need to migrate them from webforms to MVC. My question is.. Do I need to create a template for each report? Is that correct? If not, how can I do?

For example:

I have a report that should list the daily movement (production) of a company warehouse employee...the data that will be returned are:

Usuário (Login no sistema):  
Nome do Usuário: 
Quantidade de requisições atendidas: 
Quantidade de itens atendidos:

Today, within my system, I have the User object, would it be interesting to model this report? Since I will only use it in this location.

1 answer

2

Ideally you would create Viewmodels for your reports, but for performance and resource allocation it is best to keep queries in the database. The example you passed is a simple case and the query would not be too heavy depending on the volume.

But there may be situations where by the volume of data and the involvement of various schemas, Databases and more complex filters, you need to use views and even auxiliary tables only to store the mass generated for the display of other reports.

Particularly, even for the reports in Reportviewer, I try to keep all Datasource queries in Stored Procedures. Facilitates maintenance and reuse, in the case of migrations like yours, is half the way.

The Viewmodel for your example could be like this:

public class ProducaoViewModel {
   [Display(Name="Usuário (Login no sistema)")]
   public string LoginUsuario {get; set;}

   [Display(Name="Nome do Usuário")]
   public string NomeUsuario {get; set;}

   [Display(Name="Quantidade de requisições atendidas")]
   public int QtdRequisicoesAtendidas {get; set;} 

   [Display(Name="Quantidade de itens atendidos")]
   public int QtdItensAtendidos {get; set;}
}
  • But in case, I would have to create in a file this Viewmodel? Or I can add it to an existing class in the application?

  • See that the ProducaoViewModel is already a class. It is not recommended to have multiple classes in a single file for good practice reasons. I advise in addition to creating a file for her, add a folder "Viewmodels" to group them into one namespace.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.