vendredi 28 juillet 2017

Best Practise for every each action on the business service depends on the type of given role

I have a lot of Business Services(BS)s that read data from the database or add data to the database.

 public class BranchBS : BaseBS<BranchDT, Branch>, IBranchBS 
    {
        public BranchBS(ICXFServerConnection iCXFServerConnection, UserDT userDt = null)
            : base(iCXFServerConnection)
        {
            Visitor = userDt;
        }

        private UserDT Visitor;

        //Getting Branches by LibraryId
        public IEnumerable<BranchDT> GetByLibraryIds(List<int> libraryIds)
        {
            IBranchLibraryBS iBranchLibraryBs = new BranchLibraryBS(ContextFactory);
            List<BranchLibraryDT> lstBranchLibraryDt = (List<BranchLibraryDT>)iBranchLibraryBs.GetByIds(libraryIds, "Library.Id");
            List<BranchDT> lstBranchDt = (List<BranchDT>)GetByIds(lstBranchLibraryDt.Select(x => x.Branch));
            return lstBranchDt;
        }

        //Getting Branches by company Id
        public IEnumerable<BranchDT> GetByCompanyid(int companyId)
        {
            var lstBranch = (from b in ContextFactory.Retrieve().Branches
                             join c in ContextFactory.Retrieve().Companies on b.Branch_CompanyId equals c.Id
                             where c.Id == companyId && c.CompanyStatus == true && b.BranchStatus == true
                             select b).ToList();
            var lstBranchDt = DataTransformation.DataTransformation.ConvertSourceObjToDestinationObj<Branch, BranchDT>(lstBranch);
            return lstBranchDt;
        }
}

Every action of the BusinessService depends on Visitor field. for example, I show it on GetAll() function.

public GetAll( )
{
if (Visitor.Type==IsCompanytype)
{
     return "select..."
} 
if (Visitor.Type==IsBranchtype)
{
     return "select..."
}     
if (Visitor.Type==IsSupertype)
{
   return "select..."
}           
}

And I have approximately 20 Business Service classes and every class has approximately 5 functions. And Visitor can be in different 3 type. What is the best practice structure for this purpose?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire