I have a simple method that just takes a UINT16 and converts it to a object of boolean flags. This is so I can store a int value in the DB, but display a lot of yes/no information about hotels - ie pool / security guard / reception.
Over the time I have been working with the web app, the method has been in most places. it started in the BLL and now is in the DAL.
I put it in the DAL as then the DAL could return the flags inside the DTO rather that then having to call the method further up the stack.
I now need to access the from the Management UI (different site) and of course I now am in the position where I either need to move it or have a referance from the UI to the DAL.
This is the most simple part of the site, but has causes so may problems, I did not want 100's of boolean columns in the DB
I am thinking now of putting the logic in the DTO as it means in my case the logic of sorting out all of the flats is in there
If I understand it correctly, you can still place the method in BLL and call it from UI. If you are calling DAL from UI, you might have problesm with layers seperation later.
For ex:
In DAL
public static bool IsRoomReserved(int id)
{
//db queries
return result;
}
In BLL
public static bool IsRoomReserved(int id)
{
//write if there is any business logic
//like validating the input or manipulating data returned from DAL
return DAL.IsHotelReserved(id);
}
And from UI
bool result = BLL.IsRoomReserved(sampleid);
Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
You assessment of the problem is correct, I am thinking about moving it to the BLL. There reasons behind putting in the DAL were
1) if I have a DTO, then I need to get the INT value in the DTO and set the flags at the BLL. What I was trying to avoid (but I am not sure why now) was having a meanless INT value in the DTO once I got to the BLL and did the flag conversion. So for example
I could have an INT of 255 and 8 flags set to true, but that that point the INT value is redundant - as i just need the flags.
2) It is not business logic in the way that it is not input or output validations, it is a conversions.
I agree with your comments on Layer seperations, just at the time, this did not feel like a business logic function, as I understood business logic to be mostly validation
1) if I have a DTO, then I need to get the INT value in the DTO and set the flags at the BLL. What I was trying to avoid (but I am not sure why now) was having a meanless INT value in the DTO once I got to the BLL and did the flag conversion. So for example
I could have an INT of 255 and 8 flags set to true, but that that point the INT value is redundant - as i just need the flags.
So, my understanding is that UI layer only need flags and INT's are stored in the database. In that case, DTO should contain only boolean flag properties. All these(int to bool) conversions go into your DAL method and finally it should return DTO which is
further useful in the BLL layer. In BLL layer, you may include additional business validations orelse just pass the DTO to the UI layer.
public class Room
{
public bool IsReserved { get;set;}
}
public static Room IsRoomReserved(int id)
{
//map and do all required conversions i.e, int to bool values. for ex
Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
greecemonkey
Member
199 Points
312 Posts
Where should I put this flag method
Dec 09, 2012 10:40 AM|LINK
Hi Forum,
I have a simple method that just takes a UINT16 and converts it to a object of boolean flags. This is so I can store a int value in the DB, but display a lot of yes/no information about hotels - ie pool / security guard / reception.
Over the time I have been working with the web app, the method has been in most places. it started in the BLL and now is in the DAL.
I put it in the DAL as then the DAL could return the flags inside the DTO rather that then having to call the method further up the stack.
I now need to access the from the Management UI (different site) and of course I now am in the position where I either need to move it or have a referance from the UI to the DAL.
This is the most simple part of the site, but has causes so may problems, I did not want 100's of boolean columns in the DB
I am thinking now of putting the logic in the DTO as it means in my case the logic of sorting out all of the flats is in there
Anu suggestions or advice would be great
Graham
Go2Greece Ltd
sundeep_38
Contributor
3541 Points
604 Posts
Re: Where should I put this flag method
Dec 10, 2012 06:13 PM|LINK
If I understand it correctly, you can still place the method in BLL and call it from UI. If you are calling DAL from UI, you might have problesm with layers seperation later.
For ex:
In DAL
public static bool IsRoomReserved(int id)
{
//db queries
return result;
}
In BLL
public static bool IsRoomReserved(int id)
{
//write if there is any business logic
//like validating the input or manipulating data returned from DAL
return DAL.IsHotelReserved(id);
}
And from UI
bool result = BLL.IsRoomReserved(sampleid);
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
greecemonkey
Member
199 Points
312 Posts
Re: Where should I put this flag method
Dec 13, 2012 08:18 PM|LINK
Hi Sundeep,
You assessment of the problem is correct, I am thinking about moving it to the BLL. There reasons behind putting in the DAL were
1) if I have a DTO, then I need to get the INT value in the DTO and set the flags at the BLL. What I was trying to avoid (but I am not sure why now) was having a meanless INT value in the DTO once I got to the BLL and did the flag conversion. So for example I could have an INT of 255 and 8 flags set to true, but that that point the INT value is redundant - as i just need the flags.
2) It is not business logic in the way that it is not input or output validations, it is a conversions.
I agree with your comments on Layer seperations, just at the time, this did not feel like a business logic function, as I understood business logic to be mostly validation
Graham
Go2Greece Ltd
moises.dl
Contributor
2046 Points
628 Posts
Re: Where should I put this flag method
Dec 13, 2012 09:10 PM|LINK
Maybe I'm wrong but cant you build Utility classes to be called from any layer since they do not pertain to any one topic in general?
MOIhawk
sundeep_38
Contributor
3541 Points
604 Posts
Re: Where should I put this flag method
Dec 13, 2012 11:23 PM|LINK
So, my understanding is that UI layer only need flags and INT's are stored in the database. In that case, DTO should contain only boolean flag properties. All these(int to bool) conversions go into your DAL method and finally it should return DTO which is further useful in the BLL layer. In BLL layer, you may include additional business validations orelse just pass the DTO to the UI layer.
public class Room
{
public bool IsReserved { get;set;}
}
public static Room IsRoomReserved(int id)
{
//map and do all required conversions i.e, int to bool values. for ex
Room objRoom = new Room();
objRoom.IsReserved = Convert.ToBoolean(**db value**);
return Room;
}
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.