Click here to Skip to main content
13,346,895 members (26,974 online)
Click here to Skip to main content

Stats

52.5K views
1.6K downloads
68 bookmarked
Posted 16 Apr 2012

Populating a business logical layer from Stored Procedures

, 22 Sep 2014
A brief look at a technique mapping tables to a basic business layer.
doPersistence
doPersistence.csproj.user
doPersistence.csproj.vspscc
obj
Debug
Release
Properties
doLogicCode
bin
Debug
doLogicCode.vshost.exe.manifest
doLogicCode.csproj.vspscc
obj
x86
Debug
doLogicCode.frmCodeGenerator.resources
doLogicCode.Properties.Resources.resources
Properties
Test
doLogic
bin
Debug
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
Release
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
doLogic.dll
doLogic.pdb
ResolveAssemblyReference.cache
TempPE
Release
DesignTimeResolveAssemblyReferencesInput.cache
doLogic.dll
doLogic.pdb
ResolveAssemblyReference.cache
TempPE
Properties
doLogicCode
bin
Debug
doLogicCode.exe
doLogicCode.pdb
doLogicCode.vshost.exe
doLogicCode.vshost.exe.manifest
doPersistence.dll
doPersistence.pdb
obj
x86
Debug
DesignTimeResolveAssemblyReferencesInput.cache
doLogicCode.exe
doLogicCode.frmCodeGenerator.resources
doLogicCode.pdb
doLogicCode.Properties.Resources.resources
GenerateResource.read.1.tlog
GenerateResource.write.1.tlog
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Properties
doPersistence
bin
Debug
doPersistence.dll
doPersistence.pdb
Release
doPersistence.dll
doPersistence.pdb
doPersistence.csproj.vspscc
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.dll
doPersistence.pdb
TempPE
Release
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.dll
doPersistence.pdb
TempPE
Properties
Test.suo
TestSite
Account
App_Data
bin
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
TestSite.dll
TestSite.pdb
Global.asax
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ResolveAssemblyReference.cache
TempPE
TestSite.dll
TestSite.pdb
Release
CSAutoParameterize
original
Account
transformed
Account
Database
DesignTimeResolveAssemblyReferencesInput.cache
Package
PackageTmp
Account
bin
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
TestSite.dll
TestSite.pdb
Global.asax
Scripts
Styles
ResolveAssemblyReference.cache
TempPE
TestSite.dll
TestSite.pdb
TransformWebConfig
original
transformed
Account
Properties
Scripts
Styles
TestSite.csproj.user
doLogic.dll
doPersistence.dll
doPersistence.dll
doLogic.dll
doPersistence.dll
TestSite.dll
Global.asax
TestSite.csproj.user
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
DesignTimeResolveAssemblyReferencesInput.cache
doLogic.dll
doLogic.pdb
ResolveAssemblyReference.cache
DesignTimeResolveAssemblyReferencesInput.cache
doLogic.dll
doLogic.pdb
ResolveAssemblyReference.cache
doPersistence.dll
doPersistence.pdb
doPersistence.dll
doPersistence.pdb
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.dll
doPersistence.pdb
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.dll
Test.suo
doLogic.dll
doLogic.pdb
doPersistence.dll
doPersistence.pdb
TestSite.dll
TestSite.pdb
Global.asax
DesignTimeResolveAssemblyReferencesInput.cache
ResolveAssemblyReference.cache
TestSite.dll
TestSite.pdb
DesignTimeResolveAssemblyReferencesInput.cache
ResolveAssemblyReference.cache
TestSite.dll
TestSite.pdb
TestSite.csproj.user
PersistenceTest_orig
Account
App_Code
App_Data
Bin
Persistence.pdb
Global.asax
Scripts
Styles
Persistence
bin
Debug
doPersistence.pdb
Persistence.pdb
Release
doPersistence.pdb
doPersistence.csproj.vspscc
obj
Debug
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.csprojResolveAssemblyReference.cache
doPersistence.pdb
Persistence.pdb
TempPE
Release
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.pdb
TempPE
Persistence.csproj.user
Properties
PersistenceTest_orig.v11.suo
CodeGenerator
bin
Debug
doLogicCode.pdb
doLogicCode.vshost.exe.manifest
doPersistence.pdb
Persistence.pdb
CodeGenerator.csproj.vspscc
obj
x86
Debug
CodeGenerator.csproj.GenerateResource.Cache
CodeGenerator.csprojResolveAssemblyReference.cache
CodeGenerator.frmCodeGenerator.resources
CodeGenerator.Properties.Resources.resources
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
doLogicCode.csproj.GenerateResource.Cache
doLogicCode.csprojResolveAssemblyReference.cache
doLogicCode.pdb
TempPE
Properties
AjaxControlToolkit.dll
Persistence.dll
Persistence.pdb
Global.asax
doPersistence.dll
doPersistence.pdb
Persistence.dll
Persistence.pdb
doPersistence.dll
doPersistence.pdb
doPersistence.csproj.vspscc
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.csprojResolveAssemblyReference.cache
doPersistence.dll
doPersistence.pdb
Persistence.dll
Persistence.pdb
DesignTimeResolveAssemblyReferencesInput.cache
doPersistence.dll
doPersistence.pdb
Persistence.csproj.user
PersistenceTest_orig.v11.suo
doLogicCode.exe
doLogicCode.pdb
doLogicCode.vshost.exe
doLogicCode.vshost.exe.manifest
doPersistence.dll
doPersistence.pdb
Persistence.dll
Persistence.pdb
CodeGenerator.csproj.vspscc
CodeGenerator.csproj.GenerateResource.Cache
CodeGenerator.csprojResolveAssemblyReference.cache
CodeGenerator.frmCodeGenerator.resources
CodeGenerator.Properties.Resources.resources
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
doLogicCode.csproj.GenerateResource.Cache
doLogicCode.csprojResolveAssemblyReference.cache
doLogicCode.exe
doLogicCode.pdb
Properties.Resources.Designer.cs.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Persistence;

namespace doLogic
{
    public class Managers : PersistentList<Manager>
    {
        public static Managers For(Location location)
        {
            return Managers.ForLocation(location.ClientCode, location.LocID);
        }

        public static Managers For(Division division)
        {
            return Managers.ForDivision(division.ClientCode, division.DivID);
        }

        public static Managers For(Client client)
        {
            return Managers.For(client.ClientCode);
        }

        public static Managers For(int clientCode)
        {
            return new Managers(clientCode);
        }

        public static Managers ForLocation(int clientCode, int locationID)
        {
            Managers list = new Managers();
            list.ClientCode = clientCode;
            list.LocationID = locationID;
            list.Load("ForLocation");
            return list;
        }

        public static Managers ForDivision(int clientCode, int divisionID)
        {
            Managers list = new Managers();
            list.ClientCode = clientCode;
            list.DivisionID = divisionID;
            list.Load("ForDivision");
            return list;
        }

        public Managers Matching(string searchCriteria)
        {
            if (searchCriteria.IsEmpty())
                return this;

            Managers list = new Managers();

            foreach (Manager m in this)
                if (m.Equals(searchCriteria))
                    list.Add(m);
            return list;
        }

        internal Managers() { }

        private Managers(int clientCode)
        {
            this.ClientCode = clientCode;
            this.Load("ForClient");
        }

        public void Delete(int managerID)
        {
            Manager m = this.ItemById(managerID);
            if (m != null)
                this.Remove(m);

            m = new Manager();
            m.ManagerID = managerID;
            Database.Delete(m);
        }

        public int ClientCode { get; set; }
        public int LocationID { get; set; }
        public int DivisionID { get; set; }
    }

    [Persistable("Managers", "ManagerID", false)]
    public class Manager
    {
        public static void AssignToDivision(int divisionID, int managerID, bool isPrimary)
        {
            DivisionManager.Store(divisionID, managerID, isPrimary);
        }

        public void AssignToDivision(int divisionID, bool isPrimary)
        {
            if (this.ManagerID == 0)
                this.Store();
            DivisionManager.Store(divisionID, this.ManagerID, isPrimary);
        }

        public static void UnassignFromDivision(int divisionID, int managerID)
        {
            DivisionManager.Delete(divisionID, managerID);
        }

        public void UnassignFromDivision(int divisionID)
        {
            DivisionManager.Delete(divisionID, this.ManagerID);
        }

        public static void AssignToLocation(int locationID, int managerID, bool isPrimary)
        {
            LocationManager.Store(locationID, managerID, isPrimary);
        }

        public void AssignToLocation(int locationID, bool isPrimary)
        {
            if (this.ManagerID == 0)
                this.Store();
            LocationManager.Store(locationID, this.ManagerID, isPrimary);
        }

        public static void UnassignFromLocation(int locationID, int managerID)
        {
            LocationManager.Delete(locationID, managerID);
        }

        public void UnassignFromLocation(int locationID)
        {
            LocationManager.Delete(locationID, this.ManagerID);
        }

        public bool Equals(string searchCriteria)
        {
            if (this.FirstName.StartsWith(searchCriteria, StringComparison.OrdinalIgnoreCase))
                return true;
            else if (this.LastName.StartsWith(searchCriteria, StringComparison.OrdinalIgnoreCase))
                return true;
            else if (this.Title.ToLower().Contains(searchCriteria.ToLower()))
                return true;
            else if (this.Phone.Contains(searchCriteria))
                return true;
            else if (this.Email.ToLower().Contains(searchCriteria.ToLower()))
                return true;

            return false;
        }

        public static Manager Load(int managerID, Connection cn)
        {
            return new Manager(managerID, cn);
        }

        //constructors
        public Manager() { }

        public Manager(int managerID)
        {
            ManagerID = managerID;
            Database.Load(this);
        }

        private Manager(int managerID, Connection cn)
        {
            this.ManagerID = managerID;
            Database.Load(this, cn);
        }

        public string PhoneFormatted
        {
            get
            {
                return Phone.ToPhoneFormat();
            }
            set
            {
                Phone = value.ToNumbersOnly().TruncateTo(10);
            }
        }

        public string FullName
        {
            get
            {
                return String.Format("{0} {1}", FirstName, MiddleName).Trim() + " " + LastName;
            }
        }

        //persistent properties
        public int ManagerID { get; set; }
        public int ClientCode { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string MiddleName { get; set; }
        public string Title { get; set; }
        private string _phone = "";
        public string Phone { get { return _phone; } set { _phone = value.ToNumbersOnly(); } }
        public string Extension { get; set; }
        public string Email { get; set; }

        public int Store() { return Database.Store(this); }
        //public void Load() { Database.Load(this); }
        //public bool Delete() { return Database.Delete(this); }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

andrewbb@gmail.com
Architect
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 22 Sep 2014
Article Copyright 2012 by andrewbb@gmail.com
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid