Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using _09.Common_Type_System;
- class Customer : ICloneable, IComparable<Customer>
- {
- public string FirstName { get; set; }
- public string MiddleName { get; set; }
- public string LastName { get; set; }
- public string EGN { get; set; }
- public string Address { get; set; }
- public string MobilePhone { get; set; }
- public string Email { get; set; }
- public List<Payment> Payments { get; set; }
- public CustomerType CustType;
- public Customer()
- {
- }
- public Customer(string FirstName, string MiddleName, string LastName, string EGN, string Address, string MobilePhone, string Email, List<Payment> Payments, CustomerType customer)
- {
- this.FirstName = FirstName;
- this.MiddleName = MiddleName;
- this.LastName = LastName;
- this.EGN = EGN;
- this.Address = Address;
- this.MobilePhone = MobilePhone;
- this.Email = Email;
- this.Payments = Payments;
- this.CustType = customer;
- }
- public override bool Equals(object obj)
- {
- Customer customer = obj as Customer;
- if (!Object.Equals(this.FirstName, customer.FirstName))
- {
- return false;
- }
- if (!Object.Equals(this.MiddleName, customer.MiddleName))
- {
- return false;
- }
- if (!Object.Equals(this.LastName, customer.LastName))
- {
- return false;
- }
- if (!Object.Equals(this.EGN, customer.EGN))
- {
- return false;
- }
- if (!Object.Equals(this.Address, customer.Address))
- {
- return false;
- }
- if (!Object.Equals(this.MobilePhone, customer.MobilePhone))
- {
- return false;
- }
- if (!Object.Equals(this.Email, customer.Email))
- {
- return false;
- }
- if (!Object.Equals(this.Payments, customer.Payments))
- {
- return false;
- }
- if (!Object.Equals(this.CustType, customer.CustType))
- {
- return false;
- }
- return true;
- }
- public static bool operator ==(Customer customer1, Customer customer2)
- {
- return customer1.Equals(customer2);
- }
- public static bool operator !=(Customer customer1, Customer customer2)
- {
- return !(customer1.Equals(customer2));
- }
- public override int GetHashCode()
- {
- string hashCode = this.FirstName + this.LastName + this.MiddleName + this.EGN;
- return hashCode.GetHashCode();
- }
- public object Clone()
- {
- Customer newCustomer = new Customer();
- newCustomer.FirstName = (string)this.FirstName;
- newCustomer.MiddleName = (string)this.MiddleName;
- newCustomer.LastName = (string)this.LastName;
- newCustomer.EGN = (string)this.EGN;
- newCustomer.Address = (string)this.Address;
- newCustomer.MobilePhone = (string)this.MobilePhone;
- newCustomer.Email = (string)this.Email;
- newCustomer.CustType = this.CustType;
- Payment pay1 = new Payment("Motherboard", 254.99m);
- newCustomer.Payments.Add(pay1);
- //foreach (var element in this.Payments)
- //{
- // newCustomer.Payments.Add(new Payment { ProductName = element.ProductName, Price = element.Price });
- //}
- return newCustomer;
- }
- public int CompareTo(Customer other)
- {
- string thisFullName = string.Format("{0} {1} {2}", this.FirstName, this.MiddleName, this.LastName);
- string otherFullName = string.Format("{0} {1} {2}", other.FirstName, other.MiddleName, other.LastName);
- if (thisFullName.CompareTo(otherFullName) != 0)
- {
- return thisFullName.CompareTo(otherFullName);
- }
- else
- {
- return this.EGN.CompareTo(other.EGN);
- }
- }
- //public override string ToString()
- //{
- // string Payments = this.Payments.ToString();
- // return String.Format("Firstname: {0} Middlename: {1} Lastname: {2} EGN: {3} Address: {4} Mobile Phone: {5} Email: {6} Payments: {7} Customer Type: {8}", this.FirstName, this.MiddleName, this.LastName, this.EGN, this.Address, this.MobilePhone, this.Email, Payments, this.CustType);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement