Portfolio

Thursday, December 24, 2015

Building the Customer Class: Customer Management System Part 2




 Building the Customer Class

I've learned how to figure out in building the customer class to build the Customer Management System. 

In the project solution you need to add a class library to build all your necessary classes, which include the customer class. 

Next, what you want to do is add all the necessary properties, such as the Customer id, First name, Last Name, Email Address, Address, Full name and Instance Count.  A short cut snippet can be done by typing prop tab tab so Visual Studio can automatically create the property getter and setter.  In the beginning under the Customer class I've created some constructors for the customer id.  If you don't need constructors you don't need to do it, but only if it's really necessary. 

I've also created some methods, which include the retrieve method(to retrieve one customer by id), another retrieve method to get a list of customers, a save method(a boolean expression set to true to save a customer's data),  and a validate method to validate the customer's last name and email.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LMS.BL
{
    public class Customer
    {
        public Customer()
        {

        }
        public Customer(int customerId)
        {
            this.CustomerId = customerId;

        }
        public static int InstanceCount { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
        public string EmailAddress { get; set; }
        public int CustomerId { get; private set; }
        public string FullName
        {
            get
            {
                string fullName = LastName;
                if (!string.IsNullOrWhiteSpace(FirstName))
                {
                    if (!string.IsNullOrWhiteSpace(fullName))
                    {
                        fullName += ", ";
                    }
                    fullName += FirstName;
                }
                return fullName;
            }
        }
        //Retrieve one customer
        public Customer Retrieve(int customerId)
        {
            //Code that retrieves the defined customer
            return new Customer();
        }
        //Retrieve a list of customers
        public List<Customer>Retrieve()
            {
            //Code that retrieves a list of customers
            return new List<Customer>();
            }
        //Saves customer
        public bool Save()
        {
            return true;
        }



        public bool Validate()
        {
            var isValid = true;

            if (!string.IsNullOrWhiteSpace(LastName)) isValid = false;
            if (!string.IsNullOrWhiteSpace(EmailAddress)) isValid = false;

            return isValid;
        }

    }
}

No comments:

Post a Comment