How popular is Reportdatasource() object in a webform.aspx?

Asked

Viewed 71 times

0

As an example below follows the example of the Entity, Interface, Repositorio and the Controller of the MVC system. In sequence the code of a formulário webform.aspx what use to display the Pedido usando o ReportViewer, the problem is that when I try to display the request always returns Null. When debugging the system does not arrive at the Repositorio, the impression I get is that the way I’m doing it works when it’s a Controller and fails when it’s a Webform.

With this Entity, Interface and Repository structure how do I popular the object ReportDataSource() in a Webform form ?

REQUESTED ENTITY:

public class Pedido
    {
        [Key]
        public int PedidoID { get; set; }
        public DateTime? DataPedido { get; set; }
    }

INTERFACE:

public interface IPedido: IDisposable
    {
        Pedido ObterPedidoPorID(int pPedidoID);
    }

REPOSITORY:

public class PedidoRepositorio: IPedido
    {
        private readonly ctx _repositorio = new ctx();
        private bool disposed = false;

        public Pedido ObterPedidoPorID(int pPedidoID)
        {

                return _repositorio.Pedidos.FirstOrDefault(c => c.PedidoID == pPedidoID);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    _repositorio.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }

CONTROLLER:

public class PedidoController : Controller
    {
        private IPedido _IRepositorio;

        public PedidoController()
            : this(new PedidoRepositorio())
        { }

        public PedidoController(IPedido repositorio)
        {
            _IRepositorio = repositorio;
        }


        [HttpGet]
        public ActionResult Editar(int pPedidoID)
        {
            try
            {
                Pedido _pedido = _IRepositorio.ObterPedidoPorID(pPedidoID);
                return View(_pedido);
            }
            catch
            {
                return View(new Pedido());
            }
        }
    }

REPORT - Request.aspx

public partial class Pedido : System.Web.UI.Page
    {
        public IPedido _IRepositorio;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int _PedidoID = 4;
                var _pedido = _IRepositorio.ObterPedidoPorID(_PedidoID);

                var reportDS = new ReportDataSource();
                reportDS.Name = "dsPedido";
                reportDS.Value = _pedido;

                rptPedido.LocalReport.DataSources.Add(reportDS);
                rptPedido.LocalReport.ReportPath = "Areas/Administrativo/Reports/Pedido.rdlc";
            }
        }
    }

inserir a descrição da imagem aqui

  • _IRepositorio is not being assigned the instance???

  • Thus IPedido _IRepositorio = new IPedido(); makes a mistake: cannot be instained abstract class or an interface and so `Pedidorepositorio _Irepositorio = new Pedidorepositorio(); it works but I didn’t want to access the repository class directly, since I have an interface for it.

  • there’s something wrong with your code...

  • How are you solving the addiction injection? You need to use the simpleInjector or Ninject for this ... With one of these frameworks configured you can indicate that your Ipedido will be solved with the Request implementation()

  • @Virgilio Novic yes, there’s probably something wrong and I don’t know which one, for now I’m creating the instance this way.

  • @Lucas Lopes unaware of these frameworks simpleInjector ou Ninject

Show 1 more comment
No answers

Browser other questions tagged

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