Skip to content

Commit 26bd348

Browse files
committed
Clean up!!
1 parent 304de16 commit 26bd348

File tree

78 files changed

+729
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+729
-1214
lines changed

Diff for: MyHome.DataClasses/Expense.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace MyHome.DataClasses
44
{
5-
public class Expense: Transaction
5+
public class Expense : Transaction
66
{
77
public Expense()
88
{
@@ -19,13 +19,13 @@ public Expense(decimal amount, DateTime date, ExpenseCategory expenseCategory,
1919
Method = paymentMethod;
2020
}
2121

22-
public Expense(decimal amount, DateTime date, int categoryID, int methodID, string comments)
22+
public Expense(decimal amount, DateTime date, int categoryId, int methodId, string comments)
2323
{
2424
Amount = amount;
25-
CategoryId = categoryID;
25+
CategoryId = categoryId;
2626
Comments = comments;
2727
Date = date;
28-
PaymentMethodId = methodID;
28+
PaymentMethodId = methodId;
2929
}
3030

3131
///// <summary>
@@ -64,19 +64,25 @@ public Expense(decimal amount, DateTime date, int categoryID, int methodID, stri
6464

6565
public override bool Equals(object obj)
6666
{
67-
var expenseComparing = (Expense) obj;
67+
var expenseComparing = (Expense)obj;
68+
if (expenseComparing == null)
69+
{
70+
return false;
71+
}
6872

69-
return ((Amount == expenseComparing.Amount) &&
70-
((Category == null && expenseComparing.Category == null) || Category.Equals(expenseComparing.Category)) &&
71-
(Comments == expenseComparing.Comments) &&
72-
(Date == expenseComparing.Date) &&
73-
(Id == expenseComparing.Id) &&
74-
((Method == null && expenseComparing.Method == null) || Method.Equals(expenseComparing.Method)));
73+
return Amount == expenseComparing.Amount &&
74+
(Category == null && expenseComparing.Category == null || Category?.Equals(expenseComparing.Category) == true) &&
75+
Comments == expenseComparing.Comments &&
76+
Date == expenseComparing.Date &&
77+
Id == expenseComparing.Id &&
78+
(Method == null && expenseComparing.Method == null || Method?.Equals(expenseComparing.Method) == true);
7579
}
7680

7781
public override int GetHashCode()
7882
{
79-
return new {Id, Amount, Category, Comments, Date, Method}.GetHashCode();
83+
// ReSharper disable NonReadonlyMemberInGetHashCode
84+
return new { Id, Amount, Category, Comments, Date, Method }.GetHashCode();
85+
// ReSharper restore NonReadonlyMemberInGetHashCode
8086
}
8187
}
8288
}

Diff for: MyHome.DataClasses/ExpenseCategory.cs

+2-14
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,13 @@ public ExpenseCategory(int id, string name) : base(id, name)
1212
{
1313
}
1414

15-
public int CompareTo(ExpenseCategory other)
16-
{
17-
return Name.CompareTo(other.Name);
18-
}
15+
public int CompareTo(ExpenseCategory other) => string.Compare(Name, other.Name, StringComparison.Ordinal);
1916

2017
public override string ToString()
2118
{
2219
return Name;
2320
}
2421

25-
public bool Equals(ExpenseCategory expenseCategory)
26-
{
27-
return ((Id == expenseCategory.Id) &&
28-
(Name == expenseCategory.Name));
29-
}
30-
31-
public override int GetHashCode()
32-
{
33-
return base.GetHashCode();
34-
}
22+
public bool Equals(ExpenseCategory expenseCategory) => Id == expenseCategory.Id && Name == expenseCategory.Name;
3523
}
3624
}

Diff for: MyHome.DataClasses/Extensions.cs

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
namespace MyHome.DataClasses
22
{
33
/// <summary>
4-
/// Conatains extension methods for the types defined in the MyHome.DataClasses namespace
4+
/// Contains extension methods for the types defined in the MyHome.DataClasses namespace
55
/// </summary>
66
public static class Extensions
77
{
8-
#region Expense Extensions
9-
108
/// <summary>
119
/// Makes a shallow copy of the expense
1210
/// </summary>
@@ -19,10 +17,6 @@ public static Expense Copy(this Expense orginalExpense)
1917
{ CategoryId = orginalExpense.CategoryId, PaymentMethodId = orginalExpense.PaymentMethodId };
2018
}
2119

22-
#endregion
23-
24-
#region Income Extensions
25-
2620
/// <summary>
2721
/// Makes a shallow copy of the income
2822
/// </summary>
@@ -35,10 +29,6 @@ public static Income Copy(this Income orginalIncome)
3529
{ CategoryId = orginalIncome.CategoryId, PaymentMethodId = orginalIncome.PaymentMethodId };
3630
}
3731

38-
#endregion
39-
40-
#region ExpenseCategory Extensions
41-
4232
/// <summary>
4333
/// Makes a shallow copy of the ExpenseCategory
4434
/// </summary>
@@ -49,10 +39,6 @@ public static ExpenseCategory Copy(this ExpenseCategory originalExpenseCategory)
4939
return new ExpenseCategory(originalExpenseCategory.Id, originalExpenseCategory.Name);
5040
}
5141

52-
#endregion
53-
54-
#region IncomeCategory Extensions
55-
5642
/// <summary>
5743
/// Makes a shallow copy of the IncomeCategory
5844
/// </summary>
@@ -63,10 +49,6 @@ public static IncomeCategory Copy(this IncomeCategory orginalIncomeCategory)
6349
return new IncomeCategory(orginalIncomeCategory.Id, orginalIncomeCategory.Name);
6450
}
6551

66-
#endregion
67-
68-
#region PaymentMethod Extensions
69-
7052
/// <summary>
7153
/// Makes a shallow copy of the PaymentMethod
7254
/// </summary>
@@ -76,7 +58,5 @@ public static PaymentMethod Copy(this PaymentMethod orginalPaymentMethod)
7658
{
7759
return new PaymentMethod(orginalPaymentMethod.Id, orginalPaymentMethod.Name);
7860
}
79-
80-
#endregion
8161
}
8262
}

Diff for: MyHome.DataClasses/Income.cs

+17-23
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace MyHome.DataClasses
44
{
55
public class Income : Transaction
66
{
7-
#region Properties
8-
97
///// <summary>
108
///// The amount of the income
119
///// </summary>
@@ -39,10 +37,6 @@ public class Income : Transaction
3937
public new int CategoryId { get; set; }
4038
public new int PaymentMethodId { get; set; }
4139

42-
#endregion
43-
44-
#region C'Tor
45-
4640
public Income()
4741
{
4842
}
@@ -58,36 +52,36 @@ public Income(decimal amount, DateTime date, IncomeCategory incomeCategory,
5852
Method = paymentMethod;
5953
}
6054

61-
public Income(decimal amount, DateTime date, int categoryID, int methodID, string comments)
55+
public Income(decimal amount, DateTime date, int categoryId, int methodId, string comments)
6256
{
6357
Amount = amount;
64-
CategoryId = categoryID;
58+
CategoryId = categoryId;
6559
Comments = comments;
6660
Date = date;
67-
PaymentMethodId = methodID;
61+
PaymentMethodId = methodId;
6862
}
6963

70-
#endregion
71-
72-
#region Override Methods
73-
7464
public override bool Equals(object obj)
7565
{
76-
Income incomeComparing = (Income)obj;
77-
78-
return ((Amount == incomeComparing.Amount) &&
79-
((Category == null && incomeComparing.Category == null) || Category.Equals(incomeComparing.Category)) &&
80-
(Comments == incomeComparing.Comments) &&
81-
(Date == incomeComparing.Date) &&
82-
(Id == incomeComparing.Id) &&
83-
((Method == null && incomeComparing.Method == null) || Method.Equals(incomeComparing.Method)));
66+
var incomeComparing = (Income)obj;
67+
if (incomeComparing == null)
68+
{
69+
return false;
70+
}
71+
72+
return Amount == incomeComparing.Amount &&
73+
(Category == null && incomeComparing.Category == null || Category?.Equals(incomeComparing.Category) == true) &&
74+
Comments == incomeComparing.Comments &&
75+
Date == incomeComparing.Date &&
76+
Id == incomeComparing.Id &&
77+
(Method == null && incomeComparing.Method == null || Method?.Equals(incomeComparing.Method) == true);
8478
}
8579

8680
public override int GetHashCode()
8781
{
82+
// ReSharper disable NonReadonlyMemberInGetHashCode
8883
return new { Id, Amount, Category, Comments, Date, Method }.GetHashCode();
84+
// ReSharper restore NonReadonlyMemberInGetHashCode
8985
}
90-
91-
#endregion
9286
}
9387
}

Diff for: MyHome.DataClasses/IncomeCategory.cs

+3-18
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,10 @@ public IncomeCategory(int id, string name) : base(id, name)
1212
{
1313
}
1414

15-
public int CompareTo(IncomeCategory other)
16-
{
17-
return Name.CompareTo(other.Name);
18-
}
15+
public int CompareTo(IncomeCategory other) => string.Compare(Name, other.Name, StringComparison.Ordinal);
1916

20-
public override string ToString()
21-
{
22-
return Name;
23-
}
17+
public override string ToString() => Name;
2418

25-
public bool Equals(IncomeCategory incomeCategory)
26-
{
27-
return ((Id == incomeCategory.Id) &&
28-
(Name == incomeCategory.Name));
29-
}
30-
31-
public override int GetHashCode()
32-
{
33-
return base.GetHashCode();
34-
}
19+
public bool Equals(IncomeCategory incomeCategory) => Id == incomeCategory.Id && Name == incomeCategory.Name;
3520
}
3621
}

Diff for: MyHome.DataClasses/PaymentMethod.cs

+3-18
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,10 @@ public PaymentMethod(int id, string name) : base(id, name)
1212
{
1313
}
1414

15-
public int CompareTo(PaymentMethod other)
16-
{
17-
return Name.CompareTo(other.Name);
18-
}
15+
public int CompareTo(PaymentMethod other) => string.Compare(Name, other.Name, StringComparison.Ordinal);
1916

20-
public override string ToString()
21-
{
22-
return Name;
23-
}
17+
public override string ToString() => Name;
2418

25-
public bool Equals(PaymentMethod paymentMethod)
26-
{
27-
return ((Id == paymentMethod.Id) &&
28-
(Name == paymentMethod.Name));
29-
}
30-
31-
public override int GetHashCode()
32-
{
33-
return base.GetHashCode();
34-
}
19+
public bool Equals(PaymentMethod paymentMethod) => Id == paymentMethod.Id && Name == paymentMethod.Name;
3520
}
3621
}

Diff for: MyHome.DataRepositories/ExpenseRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Create(Expense expense)
7575
_context.SaveChanges();
7676
}
7777

78-
private void CleanUpForEF(Expense expense)
78+
private static void CleanUpForEF(Expense expense)
7979
{
8080
if (expense.CategoryId > 0)
8181
{

Diff for: MyHome.DataRepositories/GeneralCategoryHandler.cs

+14-17
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ public GeneralCategoryHandler(AccountingDataContext dataContext)
1616

1717
public IEnumerable<string> GetAllCategoryNames()
1818
{
19-
List<string> categoryNames = new List<string> {"Total Expenses"};
19+
var categoryNames = new List<string> { "Total Expenses" };
2020
categoryNames.AddRange(_dataContext.ExpenseCategories.Select(c => c.Name));
2121
categoryNames.Add("Total Income");
2222

23-
foreach (
24-
string incomeCategoryName in
25-
_dataContext.IncomeCategories.Select(c => c.Name))
23+
foreach (var incomeCategoryName in _dataContext.IncomeCategories.Select(c => c.Name))
2624
{
2725
if (categoryNames.Contains(incomeCategoryName))
2826
{
29-
categoryNames[categoryNames.IndexOf(incomeCategoryName)] = string.Format("{0} - {1}",
30-
incomeCategoryName, "Expense");
31-
categoryNames.Add(string.Format("{0} - {1}", incomeCategoryName, "Income"));
27+
categoryNames[categoryNames.IndexOf(incomeCategoryName)] = $"{incomeCategoryName} - Expense";
28+
categoryNames.Add($"{incomeCategoryName} - Income");
3229
}
3330
else
3431
{
@@ -43,18 +40,18 @@ public IEnumerable<string> GetAllCategoryNames(string categoryType)
4340
{
4441
switch (categoryType.ToLower())
4542
{
46-
case ("expense"):
47-
{
48-
return _dataContext.ExpenseCategories.Select(c => c.Name).ToList();
49-
}
50-
case ("income"):
51-
{
52-
return _dataContext.IncomeCategories.Select(c => c.Name).ToList();
43+
case "expense":
44+
{
45+
return _dataContext.ExpenseCategories.Select(c => c.Name).ToList();
46+
}
47+
case "income":
48+
{
49+
return _dataContext.IncomeCategories.Select(c => c.Name).ToList();
5350
}
5451
default:
55-
{
56-
return new List<string>();
57-
}
52+
{
53+
return new List<string>();
54+
}
5855
}
5956
}
6057
}

Diff for: MyHome.DataRepositories/IncomeRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Create(Income income)
7777
_context.SaveChanges();
7878
}
7979

80-
private void CleanUpForEF(Income income)
80+
private static void CleanUpForEF(Income income)
8181
{
8282
if (income.CategoryId > 0)
8383
{

Diff for: MyHome.DataRepositories/MyHome.DataRepositories.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
<Project>{5424771d-5cd2-4e89-883d-46343dc4b543}</Project>
7474
<Name>MyHome.Persistence</Name>
7575
</ProjectReference>
76-
<ProjectReference Include="..\FrameWork\MyHome.Infrastructure.csproj">
77-
<Project>{89C7A321-B6DC-455A-B99F-594A9570FB20}</Project>
78-
<Name>MyHome.Infrastructure</Name>
79-
</ProjectReference>
8076
<ProjectReference Include="..\MyHome.DataClasses\MyHome.DataClasses.csproj">
8177
<Project>{977477BF-6CCA-4FFE-AA4B-B77F9B7D2C68}</Project>
8278
<Name>MyHome.DataClasses</Name>

0 commit comments

Comments
 (0)