109 lines
4.3 KiB
C#
109 lines
4.3 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Gremlin_BlazorServer.Data.EntityClasses;
|
|
|
|
public class Account : IMetadata
|
|
//: IEquatable<Account>
|
|
{
|
|
//primary key:
|
|
[Required] public uint AccountId { get; set; }
|
|
|
|
//foreign keys:
|
|
// [Required] public uint ParentAccountId { get; set; }
|
|
public string? AccountTypeCode { get; set; }
|
|
public string? SubMarketCode { get; set; }
|
|
|
|
//navigation properties:
|
|
public AccountType? AccountType { get; set; }
|
|
public SubMarket? SubMarket { get; set; }
|
|
public IList<Contact>? Contacts { get; set; }
|
|
|
|
public IList<SalesRep>? SalesReps { get; set; }
|
|
// public IList<CustomDescription>? CustomDescriptions { get; set; }
|
|
|
|
//class properties:
|
|
[Required] public string? AccountName { get; set; }
|
|
public string Notes { get; set; } = string.Empty;
|
|
[Required] public string? Street { get; set; }
|
|
[Required] public uint Zip { get; set; }
|
|
[Required] public string? City { get; set; }
|
|
public string FloorOrBuilding { get; set; } = string.Empty;
|
|
public float Longitude { get; set; }
|
|
public float Latitude { get; set; }
|
|
public string PhoneNumber { get; set; } = string.Empty;
|
|
public string FaxNumber { get; set; } = string.Empty;
|
|
public string Webpage { get; set; } = string.Empty;
|
|
public string EMail { get; set; } = string.Empty;
|
|
|
|
//Agilent-specific Properties:
|
|
public uint SapAccountNumber { get; set; }
|
|
public DateTime AccountCreatedInSapOn { get; set; }
|
|
|
|
//metadata:
|
|
public DateTime DataCreationDate { get; set; } = DateTime.Now;
|
|
public DateTime DataModificationDate { get; set; } = DateTime.Now;
|
|
public DateTime DataValidFrom { get; set; } = DateTime.Now;
|
|
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
|
|
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
|
|
public uint DataVersionNumber { get; set; }
|
|
public string? DataVersionComment { get; set; } = string.Empty;
|
|
public string DataStatus { get; set; } = "Active";
|
|
|
|
//IBase
|
|
//tbd
|
|
|
|
public bool Equals(Account? other) {
|
|
if (other is null) return false;
|
|
return SapAccountNumber == other.SapAccountNumber
|
|
&& AccountName == other.AccountName
|
|
&& City == other.City
|
|
&& EMail == other.EMail
|
|
&& PhoneNumber == other.PhoneNumber
|
|
&& Street == other.Street
|
|
&& Zip == other.Zip;
|
|
}
|
|
|
|
public static bool operator ==(Account? account1, Account? account2) {
|
|
if (account1 is null || account2 is null) return false;
|
|
if (account1.SapAccountNumber == 0) return false;
|
|
if (account2.SapAccountNumber == 0) return false;
|
|
return account1.SapAccountNumber == account2.SapAccountNumber
|
|
&& account1.AccountName == account2.AccountName
|
|
&& account1.City == account2.City
|
|
&& account1.EMail == account2.EMail
|
|
&& account1.PhoneNumber == account2.PhoneNumber
|
|
&& account1.Street == account2.Street
|
|
&& account1.Zip == account2.Zip;
|
|
}
|
|
|
|
public static bool operator !=(Account? account1, Account? account2)
|
|
{
|
|
if (account1 is null || account2 is null) return false;
|
|
if (account1.SapAccountNumber == 0) return false;
|
|
if (account2.SapAccountNumber == 0) return false;
|
|
return account1.SapAccountNumber != account2.SapAccountNumber
|
|
&& account1.AccountName != account2.AccountName
|
|
&& account1.City != account2.City
|
|
&& account1.EMail != account2.EMail
|
|
&& account1.PhoneNumber != account2.PhoneNumber
|
|
&& account1.Street != account2.Street
|
|
&& account1.Zip != account2.Zip;
|
|
|
|
}
|
|
|
|
// public override bool Equals(object? obj) {
|
|
// if (obj == null) return false;
|
|
// return obj is Account && base.Equals(obj);
|
|
// }
|
|
//
|
|
// public override int GetHashCode() => $"{AccountName}:{City}:{Street}:{Zip}".GetHashCode();
|
|
|
|
public List<Account> AddIfUniqueTo(List<Account> accounts) {
|
|
if (accounts.Count > 0 && SapAccountNumber == accounts[^1].SapAccountNumber) return accounts;
|
|
|
|
if (accounts.Any(account => SapAccountNumber == account.SapAccountNumber)) return accounts;
|
|
|
|
accounts.Add(this);
|
|
return accounts;
|
|
}
|
|
} |