controller responsibility

0

I have my Model Bank

public class Banco {
   public int Id {get;set;}
   public string Nome {get;set;}
}

and my model Bank Account

public class ContaBancaria 
{
  public int Id{get;set;}
  public string Nome {get;set;}
  public Banco Banco {get;set;}
}

Let's see, for each of them I will have my controller

BancoController
ContaBancariaController

So I have a View "New AccountBanking", it is part and all your Insert / Edit / Delete actions are from my Bank AccountController. But in it I have a combo with banks listing

Who is responsible for seeking and sending me this information from the bank to this my view?

From the BancoController for having sole responsibility and when necessary to call his method to return, or in the AccountBancariaController because this data belongs to him, he has the role of listing and sending?

I do not know if it was clear, it is an example that can happen, but there can also be more than one dependency for example ...

    
asked by anonymous 17.09.2014 / 21:36

1 answer

1

To solve this type of question I usually create a layer of data access ( Dal ) and create in it the functionalities that access data.

Following this model, we would have its class BancoDAO (Data Access Object) providing the bank data referring to the desired information that relates to the Banco model, which can easily be consumed by the view.

If we wanted to make this data available in ViewBag , we could do this:

public ActionResult Index()
{
    ViewBag.Bancos = new BancoDAO().ListarBancos(); // Busca os dados dos bancos

    return View();
}
    
17.09.2014 / 21:44