GreenRock Software Code Comment

February 19, 2008

Filed under: BLL Classes — greenrocksoftware @ 11:20 am

 This code is part of an application that demonstrates our adopted approach to the separation of GUI and database. The EntityInfo tier is used as a container to carry data objects in and out of the DAL as well as holding the attribute data for BLL objects.

 This code is an example of a BLL class.

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using EntityInfo;

using DataAccess;

 

namespace BusinessLogic

{

    public class User

    {

 

        #region private members

 

        // create the DataAccess class

        private static readonly UserDB _dal = new UserDB();

 

        // EntityInfo object reference that stores User attributes

        private UserInfo _userInfo;

 

        #endregion private members

 

        #region public properties

 

        public String Login

        {

            get { return _userInfo.Login; }

            set { _userInfo.Login = value; }

        }

 

        public String Password

        {

            get { return _userInfo.Password; }

            set { _userInfo.Password = value; }

        }

 

        public String FirstName

        {

            get { return _userInfo.FirstName; }

            set { _userInfo.FirstName = value; }

        }

 

        public String LastName

        {

            get { return _userInfo.LastName; }

            set { _userInfo.LastName = value; }

        }

 

        public String Address

        {

            get { return _userInfo.Address; }

            set { _userInfo.Address = value; }

        }

 

        public String City

        {

            get { return _userInfo.City; }

            set { _userInfo.City = value; }

        }

 

        public String State

        {

            get { return _userInfo.State; }

            set { _userInfo.State = value; }

        }

 

        public String Zip

        {

            get { return _userInfo.Zip; }

            set { _userInfo.Zip = value; }

        }

 

        public String Phone

        {

            get { return _userInfo.Phone; }

            set { _userInfo.Phone = value; }

        }

 

        #endregion public properties

 

        #region constructors

 

        public User(UserInfo uInfo)

        {

            this._userInfo = uInfo;

        }

 

        public User(string login, string password)

        {

            Users users = new Users();

            this._userInfo = users.GetUser(login, password);

        }

 

        public User(string login, string password, string firstname, string lastName, string address, string city, string state, string zip, string phone)

        {

            UserInfo uInfo = new UserInfo();

            uInfo.Login = login;

            uInfo.Password = password;

            uInfo.FirstName = firstname;

            uInfo.LastName = lastName;

            uInfo.Address = address;

            uInfo.City = city;

            uInfo.State = state;

            uInfo.Zip = zip;

            uInfo.Phone = phone;

 

            this._userInfo = uInfo;

        }

 

        #endregion  constructors

 

        #region public methods

 

        public void AddUser()

        {

            if (this._userInfo != null)

            {

                Users users = new Users();

                users.AddUser(this._userInfo);

            }

        }

 

        /// <summary>

        /// Checks if a valid instance.

        /// </summary>

        public bool isValid

        {

            get

            {

                bool valid = true;

                if (this._userInfo == null)

                {

                    valid = false;

                }

                else

                {

                    if (this._userInfo.Login == string.Empty || this._userInfo.Password == string.Empty)

                    {

                        valid = false;

                    }

                }

                return valid;

            }

        }

 

        #endregion public methods

 

    }

}

 

Blog at WordPress.com.