Layered communication

Asked

Viewed 224 times

1

I have 3 layers , BLL, DAL and the Project. In the DAL layer is the ENTITY (automatically creates the Gets and Sets) and I want to use the Gets and Sets

Because when it arrives in the project layer the value and "0".

Maybe I’m a little confused the question more in the BLL code and the PROJECT has a commented line that helps to understand the problem

DAL layer

namespace DAL
{
using System;
using System.Collections.Generic;

public partial class TabUsuario
{
    public int UsuarioId { get; set; }
    public string Login { get; set; }
    public string Senha { get; set; }
    public string Nome { get; set; }
    public string Email { get; set; }
    public int PerfilId { get; set; }
    public bool Status { get; set; }
    public System.DateTime DataCriacao { get; set; }

    public virtual TabPerfil TabPerfil { get; set; }
}

}

BLL layer is login class

TabUsuario DALUsuario = new TabUsuario();

public void Login(string Usuario, string Password)
    {
        bool exite = db.TabUsuario.Any(m => m.Login == Usuario && m.Senha == Password && m.Status == true);
        if (exite == true)
        {
            //AQUI O VALOR PASSA NORMAL , O PerfilId FICA COM VALOR 1
            DALUsuario.PerfilId = db.TabUsuario.Where(m => m.Login == Usuario).Select(m => m.PerfilId).FirstOrDefault(); 
        }

        verificacao = exite;
    } 

Layer Project I have

TabUsuario DALUsuario = new TabUsuario();

if (Usuarios.Verificacao == true)
        {
            lblLogado.Visible = true;
            lblLogado.Text = "Logado com Sucesso.!";
            //AQUI O VALOR NÃO CHEGA , O PerfilId FICA COM VALOR 0
            Session.Add("PerfilUsuario", DALUsuario.PerfilId);
        }
  • 1

    you are giving a new Dalusuario object when you enter the project, then it will reset everything even. you have to catch this guy by reference.

  • @Deramon I discovered this but I don’t know how to do only know how to use the "new", I’m still studying the c# could tell me, or pass me the base I’ll go back ? Thank you.

  • taking into account that the Dalusuario object becomes a member of your BLL Layer, in your Project layer you need to instantiate an BLL Layer object, and access Dalusuario. Something like Tabusuario usuarioProject = Objbll.Dalusuario; You can see it if it’s public.

  • @Thank you Deramon. Now I get it, I went a little further in theory in case someone came in for that mistake .!

  • The reason is that you cannot use one instance variable to initialize another using a field initializer, because the execution order of the initialisers field is undefined. Base: http://stackoverflow.com/questions/14439231/a-field-initializer-cannot-reference-the-nonstatic-field-method-or-property

No answers

Browser other questions tagged

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