Removed unnecessary properties and functions from billing classes.

This commit is contained in:
Tobias Erbshäußer
2020-06-27 10:59:25 +02:00
parent 93ef81f2f3
commit 18f280968e
-267
View File
@@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
@@ -65,30 +63,6 @@ namespace UCalc.Data
City = ""; City = "";
Postcode = ""; Postcode = "";
} }
private bool Equals(Address other)
{
return Street == other.Street && HouseNumber == other.HouseNumber && City == other.City &&
Postcode == other.Postcode;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Address) obj);
}
public Address Clone()
{
return new Address
{
Street = Street,
HouseNumber = HouseNumber,
City = City,
Postcode = Postcode
};
}
} }
public class BankAccount public class BankAccount
@@ -108,28 +82,6 @@ namespace UCalc.Data
Bic = ""; Bic = "";
BankName = ""; BankName = "";
} }
private bool Equals(BankAccount other)
{
return Iban == other.Iban && Bic == other.Bic && BankName == other.BankName;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((BankAccount) obj);
}
public BankAccount Clone()
{
return new BankAccount
{
Iban = Iban,
Bic = Bic,
BankName = BankName
};
}
} }
public class Flat public class Flat
@@ -167,23 +119,10 @@ namespace UCalc.Data
return Id.GetHashCode(); return Id.GetHashCode();
// ReSharper restore NonReadonlyMemberInGetHashCode // ReSharper restore NonReadonlyMemberInGetHashCode
} }
public Flat Clone()
{
return new Flat
{
Id = Id,
Name = Name,
Size = Size
};
}
} }
public class Tenant public class Tenant
{ {
[JsonProperty(PropertyName = "id"), JsonRequired]
public Guid Id { get; set; }
[JsonProperty(PropertyName = "salutation"), JsonRequired, JsonConverter(typeof(StringEnumConverter))] [JsonProperty(PropertyName = "salutation"), JsonRequired, JsonConverter(typeof(StringEnumConverter))]
public Salutation Salutation { get; set; } public Salutation Salutation { get; set; }
@@ -216,47 +155,12 @@ namespace UCalc.Data
public Tenant() public Tenant()
{ {
Id = Guid.NewGuid();
Name = ""; Name = "";
BankAccount = new BankAccount(); BankAccount = new BankAccount();
RentedFlats = new HashSet<Flat>(); RentedFlats = new HashSet<Flat>();
CustomMessage1 = ""; CustomMessage1 = "";
CustomMessage2 = ""; CustomMessage2 = "";
} }
private bool Equals(Tenant other)
{
return Id.Equals(other.Id) && Salutation == other.Salutation && Name == other.Name &&
PersonCount == other.PersonCount && Equals(BankAccount, other.BankAccount) &&
Nullable.Equals(EntryDate, other.EntryDate) && Nullable.Equals(DepartureDate, other.DepartureDate) &&
RentedFlats.SequenceEqual(other.RentedFlats) && PaidRent == other.PaidRent &&
CustomMessage1 == other.CustomMessage1 && CustomMessage2 == other.CustomMessage2;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Tenant) obj);
}
public Tenant Clone(Dictionary<Flat, Flat> flatMapper)
{
return new Tenant
{
Id = Id,
Salutation = Salutation,
Name = Name,
PersonCount = PersonCount,
BankAccount = BankAccount.Clone(),
EntryDate = EntryDate,
DepartureDate = DepartureDate,
RentedFlats = new HashSet<Flat>(RentedFlats.Select(flat => flatMapper[flat])),
PaidRent = PaidRent,
CustomMessage1 = CustomMessage1,
CustomMessage2 = CustomMessage2
};
}
} }
public class Landlord public class Landlord
@@ -288,32 +192,6 @@ namespace UCalc.Data
Address = new Address(); Address = new Address();
BankAccount = new BankAccount(); BankAccount = new BankAccount();
} }
private bool Equals(Landlord other)
{
return Salutation == other.Salutation && Name == other.Name && MailAddress == other.MailAddress &&
Phone == other.Phone && Equals(Address, other.Address) && Equals(BankAccount, other.BankAccount);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Landlord) obj);
}
public Landlord Clone()
{
return new Landlord
{
Salutation = Salutation,
Name = Name,
MailAddress = MailAddress,
Phone = Phone,
Address = Address.Clone(),
BankAccount = BankAccount.Clone()
};
}
} }
public class House public class House
@@ -329,27 +207,6 @@ namespace UCalc.Data
Address = new Address(); Address = new Address();
Flats = new List<Flat>(); Flats = new List<Flat>();
} }
private bool Equals(House other)
{
return Equals(Address, other.Address) && Flats.SequenceEqual(other.Flats);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((House) obj);
}
public House Clone()
{
return new House
{
Address = Address.Clone(),
Flats = new List<Flat>(Flats.Select(flat => flat.Clone()))
};
}
} }
public class CostEntryDetails public class CostEntryDetails
@@ -367,29 +224,6 @@ namespace UCalc.Data
{ {
DiscountsInUnits = new List<decimal>(); DiscountsInUnits = new List<decimal>();
} }
private bool Equals(CostEntryDetails other)
{
return TotalAmount == other.TotalAmount && UnitCount == other.UnitCount &&
DiscountsInUnits.SequenceEqual(other.DiscountsInUnits);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((CostEntryDetails) obj);
}
public CostEntryDetails Clone()
{
return new CostEntryDetails
{
TotalAmount = TotalAmount,
UnitCount = UnitCount,
DiscountsInUnits = new List<decimal>(DiscountsInUnits)
};
}
} }
public class CostEntry public class CostEntry
@@ -410,30 +244,6 @@ namespace UCalc.Data
{ {
Details = new CostEntryDetails(); Details = new CostEntryDetails();
} }
private bool Equals(CostEntry other)
{
return StartDate.Equals(other.StartDate) && EndDate.Equals(other.EndDate) && Amount == other.Amount &&
Details.Equals(other.Details);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((CostEntry) obj);
}
public CostEntry Clone()
{
return new CostEntry
{
StartDate = StartDate,
EndDate = EndDate,
Amount = Amount,
Details = Details?.Clone()
};
}
} }
public enum CostDivision public enum CostDivision
@@ -490,34 +300,6 @@ namespace UCalc.Data
AffectedFlats = new HashSet<Flat>(); AffectedFlats = new HashSet<Flat>();
Entries = new List<CostEntry>(); Entries = new List<CostEntry>();
} }
private bool Equals(Cost other)
{
return Name == other.Name && Division == other.Division && AffectsAll == other.AffectsAll &&
ShiftUnrented == other.ShiftUnrented && AffectedFlats.SequenceEqual(other.AffectedFlats) &&
Entries.SequenceEqual(other.Entries) && DisplayInBill == other.DisplayInBill;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Cost) obj);
}
public Cost Clone(Dictionary<Flat, Flat> flatMapper)
{
return new Cost
{
Name = Name,
Division = Division,
AffectsAll = AffectsAll,
ShiftUnrented = ShiftUnrented,
AffectedFlats = new HashSet<Flat>(AffectedFlats.Select(flat => flatMapper[flat])),
Entries = new List<CostEntry>(Entries.Select(entry => entry.Clone())),
DisplayInBill = DisplayInBill
};
}
} }
public class Billing public class Billing
@@ -547,54 +329,5 @@ namespace UCalc.Data
Tenants = new List<Tenant>(); Tenants = new List<Tenant>();
Costs = new List<Cost>(); Costs = new List<Cost>();
} }
private bool Equals(Billing other)
{
return StartDate.Equals(other.StartDate) && EndDate.Equals(other.EndDate) &&
Landlord.Equals(other.Landlord) && House.Equals(other.House) &&
Tenants.SequenceEqual(other.Tenants) && Costs.SequenceEqual(other.Costs);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Billing) obj);
}
public Billing Clone()
{
var house = House.Clone();
var flatMapper = new Dictionary<Flat, Flat>(new ObjectReferenceEqualityComparer<Flat>());
for (var i = 0; i < House.Flats.Count; ++i)
{
flatMapper.Add(House.Flats[i], house.Flats[i]);
}
return new Billing
{
StartDate = StartDate,
EndDate = EndDate,
Landlord = Landlord.Clone(),
House = House,
Tenants = new List<Tenant>(Tenants.Select(tenant => tenant.Clone(flatMapper))),
Costs = new List<Cost>(Costs.Select(cost => cost.Clone(flatMapper)))
};
}
}
public class ObjectReferenceEqualityComparer<T> : EqualityComparer<T>
where T : class
{
public override bool Equals(T x, T y)
{
return ReferenceEquals(x, y);
}
public override int GetHashCode(T obj)
{
return RuntimeHelpers.GetHashCode(obj);
}
} }
} }