locked
a basic question on BLL , plz guide me RRS feed

  • Question

  • User852864959 posted

    Hi,

        thanks for your attention and time,

    I am new to implementing layered architecture. In my project I have UI,BLL and DAL layers. From page user id &  password go to BLL and BLL pass it to DAL. If use exisit its full record is return to BLL through DAL.

    User can be a user or a staff member, after login user go to user panel and staff go to staff panel.  My confusion is where I should check user type in BLL or record should be go login page.cs and there it should be checked and then user should be moved ?

    thanks


    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Tuesday, December 29, 2009 3:24 AM

Answers

  • User-1071856410 posted

    After checking whether User exists, Your BLL will be passing the UserEntity Object back to the login page.

    (In an ideal architecture, You will have an entity for representing the user.

    Lets say you have a UserEntity class. Now this class will have all the user's properties. Along with other fields UserEntity will have a field called UserType.)

    Now you can check the UserType from the login page itself and redirect the user accordingly.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2009 4:24 AM
  • User-1161841047 posted

    I believe the best way to return the user info object from BLL and in paeg login check for the Authorization and redirect the page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2009 4:35 AM
  • User-1071856410 posted

    @muhammedsalimp, @Yousef_Jadallah checking user type is not a business rule ? should it not be done in BLL ? secondly if we check user type in login.aspx.cs then we are again putting our business logic in page as opposed to what generally is adviced that business logic should be in BAL and not in UI layer (my BLL & DAL are seprate class libraries) ? Please guide and clarify thanks.

    Checking User type is surely a business rule. As far as possible we must incorporate business rules in BLL itself..

    But here you want to redirect user to a specific page. If you try to incorporate this logic in your class library, things will become pretty complicated. A lot of overhead will occur as you already know when you try to maintain your HTTP Session and other details in class libraries.

    So in my opinion, patterns should not be applied in such a way that it creates overhead for maintaining the application.

    After all patterns were introduced for saving time and reducing risk on your software development projects.

    That's just my opinion. I'm really looking forward to hear other's opinion on this matter

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2009 12:38 AM
  • User1753744165 posted

    What pattern are you using? Standard web forms or MVC? I assume web forms, so in that case, I would do the logic check in the page itself. However, if you want to put this in your BAL, you can manage session in there. The session will be in the Context, which you can access.

     

    I think the Context is in the Page.Context.CurrentSession or something like that.

     

    BaseUser user = BAL.Login(loginInfo);

    if (BaseUser != null) {

    Session["User"] = BaseUser;

    if (BaseUser as Staff != null) {

    Response.Redirect "Staffpage";

    }

    else {

    Response.Redirect "RegularPage";

    }

     

    Nick

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2009 9:35 AM
  • User-1161841047 posted

    Thanks for this reference Yousuf, please guide about response.redirect, can it be in class library ?

    If I am not mistaken both session and response.redirect both are not supported in class library (not appearing in telesense)

    Thanks



    I give this solutions about Session and responce.redirect as an idea , As I said before I don't prefer it and the best way to use it in GUI layer .

    also you can use it in this way System.Web.HttpContext.Current.Response.Redirect("YourPage.aspx");

    Note that it will fail when it's accessed from outside Web Application like Consol or Windows application.

    But the best way to create a method in your Class Library to return value of the (Page.aspx) to GUI .then you direct it in GUI .


    Hope that help.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 31, 2009 2:28 AM

All replies

  • User-1071856410 posted

    After checking whether User exists, Your BLL will be passing the UserEntity Object back to the login page.

    (In an ideal architecture, You will have an entity for representing the user.

    Lets say you have a UserEntity class. Now this class will have all the user's properties. Along with other fields UserEntity will have a field called UserType.)

    Now you can check the UserType from the login page itself and redirect the user accordingly.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2009 4:24 AM
  • User-1161841047 posted

    I believe the best way to return the user info object from BLL and in paeg login check for the Authorization and redirect the page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2009 4:35 AM
  • User1753744165 posted

    You should have a BaseUser class that is inherited to a StandardUser Class and a Staff class. You will then set the return type as a BaseUser from your DAL, and cast it to each type to see where you should go inside your BAL.

    If you need to add another user type (Visitor for example), you dont have to modify anything about the base class. Same thing if you need something specific to a Staff user, like Position. You can modify the Staff class, but it doesnt have to be reflected in the StandardUser class.

     

    Nick

     Edit: Also realize that you should have seperate BusinessEntities from your BusinessLogic.

    Tuesday, December 29, 2009 4:53 PM
  • User-1161841047 posted

    You should have a BaseUser class that is inherited to a StandardUser Class and a Staff class. You will then set the return type as a BaseUser from your DAL, and cast it to each type to see where you should go inside your BAL.

    If you need to add another user type (Visitor for example), you dont have to modify anything about the base class. Same thing if you need something specific to a Staff user, like Position. You can modify the Staff class, but it doesnt have to be reflected in the StandardUser class.


    Nick

     Edit: Also realize that you should have seperate BusinessEntities from your BusinessLogic.

    Thank's for your approach ,I think  It's a good way , but many time don't work fine, because the User type and permission most of times be dynamic.

    What's your opinion in these cases.

    Thank's

     

    Tuesday, December 29, 2009 5:13 PM
  • User852864959 posted

    Thanks @muhammedsalimp, @Yousef_Jadallah and @nick-w for sparing your precious time and sharing experties.

    @muhammedsalimp, @Yousef_Jadallah checking user type is not a business rule ? should it not be done in BLL ? secondly if we check user type in login.aspx.cs then we are again putting our business logic in page as opposed to what generally is adviced that business logic should be in BAL and not in UI layer (my BLL & DAL are seprate class libraries) ? Please guide and clarify thanks.


    @nick-w I got that there should be business entities for return type and the way you suggest for casting. I thing I couldn't explain my query properly. My login.aspx page pass user name and password to BLL and BLL layer pass it to DAL. If use exists this complete record is returned to DAL where user object is filled and returned to BLL. Here comes my query, if user is staff user he should be redirected to staff control panel but if user is a client user he should be redirected to clint page. Where this checking should be accured in BLL or BLL should return the user record to login page (user record that was returned from DAL) and in login page we should check user type and redirect to appropriate page ? My BLL and DAL are seprate class libraries. If you suggest this checking should be in login.aspx page here come again the quries that I have raised with @muhammedsalimp  @Yousef_Jadallah above this text. If you say it should be in BLL then BLL is a seprate class library how to manage session variables and redirect as these do not work in class library. In this case an issue is also that if authentication fails where to manage error message ? thanks to all of you for this contribution and support.


    thanks to all of you.

    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Wednesday, December 30, 2009 12:07 AM
  • User-1071856410 posted

    @muhammedsalimp, @Yousef_Jadallah checking user type is not a business rule ? should it not be done in BLL ? secondly if we check user type in login.aspx.cs then we are again putting our business logic in page as opposed to what generally is adviced that business logic should be in BAL and not in UI layer (my BLL & DAL are seprate class libraries) ? Please guide and clarify thanks.

    Checking User type is surely a business rule. As far as possible we must incorporate business rules in BLL itself..

    But here you want to redirect user to a specific page. If you try to incorporate this logic in your class library, things will become pretty complicated. A lot of overhead will occur as you already know when you try to maintain your HTTP Session and other details in class libraries.

    So in my opinion, patterns should not be applied in such a way that it creates overhead for maintaining the application.

    After all patterns were introduced for saving time and reducing risk on your software development projects.

    That's just my opinion. I'm really looking forward to hear other's opinion on this matter

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2009 12:38 AM
  • User1753744165 posted

    What pattern are you using? Standard web forms or MVC? I assume web forms, so in that case, I would do the logic check in the page itself. However, if you want to put this in your BAL, you can manage session in there. The session will be in the Context, which you can access.

     

    I think the Context is in the Page.Context.CurrentSession or something like that.

     

    BaseUser user = BAL.Login(loginInfo);

    if (BaseUser != null) {

    Session["User"] = BaseUser;

    if (BaseUser as Staff != null) {

    Response.Redirect "Staffpage";

    }

    else {

    Response.Redirect "RegularPage";

    }

     

    Nick

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2009 9:35 AM
  • User1753744165 posted

    You should have a BaseUser class that is inherited to a StandardUser Class and a Staff class. You will then set the return type as a BaseUser from your DAL, and cast it to each type to see where you should go inside your BAL.

    If you need to add another user type (Visitor for example), you dont have to modify anything about the base class. Same thing if you need something specific to a Staff user, like Position. You can modify the Staff class, but it doesnt have to be reflected in the StandardUser class.


    Nick

     Edit: Also realize that you should have seperate BusinessEntities from your BusinessLogic.

    Thank's for your approach ,I think  It's a good way , but many time don't work fine, because the User type and permission most of times be dynamic.

    What's your opinion in these cases.

    Thank's

     

     

     

     

    Im not sure what you mean by dynamic? The redirection or the type of user?

     

    Nick

    Wednesday, December 30, 2009 9:37 AM
  • User-1161841047 posted

    Im not sure what you mean by dynamic? The redirection or the type of user?

    Dear nick-w.

    yeas I mean both , but the main thing is the User Types... That mean you can't manage that way with all the user types which the Administrator of the system will be define later.


    BLL is a seprate class library how to manage session variables and redirect as these do not work in class library

    Just for future purposes if you want to user session in Classes you can use it like this:

     

    HttpContext.Current.Session["Test"] = "Value";

    Best Regards.

    Wednesday, December 30, 2009 11:28 PM
  • User852864959 posted

    Thanks for this reference Yousuf, please guide about response.redirect, can it be in class library ?

    If I am not mistaken both session and response.redirect both are not supported in class library (not appearing in telesense)

    Thanks


    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Thursday, December 31, 2009 12:54 AM
  • User-1161841047 posted

    Thanks for this reference Yousuf, please guide about response.redirect, can it be in class library ?

    If I am not mistaken both session and response.redirect both are not supported in class library (not appearing in telesense)

    Thanks



    I give this solutions about Session and responce.redirect as an idea , As I said before I don't prefer it and the best way to use it in GUI layer .

    also you can use it in this way System.Web.HttpContext.Current.Response.Redirect("YourPage.aspx");

    Note that it will fail when it's accessed from outside Web Application like Consol or Windows application.

    But the best way to create a method in your Class Library to return value of the (Page.aspx) to GUI .then you direct it in GUI .


    Hope that help.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 31, 2009 2:28 AM