Skip to content

Commit

Permalink
Rework warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAxelander committed Mar 14, 2024
1 parent dbf40f1 commit 1e7f079
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 31 deletions.
6 changes: 3 additions & 3 deletions OpenBudgeteer.Core.Data.Entities/Models/Bucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class Bucket : IEntity
[NotMapped]
public BucketVersion? CurrentVersion { get; set; }

public ICollection<BucketVersion> BucketVersions { get; set; }
public ICollection<BucketVersion>? BucketVersions { get; set; }

public ICollection<BudgetedTransaction> BudgetedTransactions { get; set; }
public ICollection<BudgetedTransaction>? BudgetedTransactions { get; set; }

public ICollection<BucketMovement> BucketMovements { get; set; }
public ICollection<BucketMovement>? BucketMovements { get; set; }
}
2 changes: 1 addition & 1 deletion OpenBudgeteer.Core.Data.Entities/Models/BucketGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class BucketGroup : IEntity
[Required]
public int Position { get; set; }

public ICollection<Bucket> Buckets { get; set; }
public ICollection<Bucket>? Buckets { get; set; }
}
2 changes: 1 addition & 1 deletion OpenBudgeteer.Core.Data.Entities/Models/BucketRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public class BucketRuleSet : IEntity

public Bucket TargetBucket { get; set; } = null!;

public ICollection<MappingRule> MappingRules { get; set; }
public ICollection<MappingRule>? MappingRules { get; set; }
}
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/BucketGroupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int Delete(Guid id)
.Include(i => i.Buckets)
.FirstOrDefault(i => i.Id == id);
if (entity == null) throw new Exception($"BucketGroup with id {id} not found.");
if (entity.Buckets.Count != 0) throw new Exception($"Cannot delete a BucketGroup with Buckets assigned to it.");
if (entity.Buckets != null && entity.Buckets.Count != 0) throw new Exception($"Cannot delete a BucketGroup with Buckets assigned to it.");

DatabaseContext.BucketGroup.Remove(entity);
return DatabaseContext.SaveChanges();
Expand All @@ -75,7 +75,7 @@ public int DeleteRange(IEnumerable<Guid> ids)
.Include(i => i.Buckets)
.Where(i => cleansedEntities.Contains(i.Id));
if (!entities.Any()) throw new Exception($"No BucketGroup found with passed IDs.");
if (entities.Any(i => i.Buckets.Count != 0)) throw new Exception($"Cannot delete a BucketGroup with Buckets assigned to it.");
if (entities.Any(i => i.Buckets != null && i.Buckets.Count != 0)) throw new Exception($"Cannot delete a BucketGroup with Buckets assigned to it.");

DatabaseContext.BucketGroup.RemoveRange(entities);
return DatabaseContext.SaveChanges();
Expand Down
12 changes: 6 additions & 6 deletions OpenBudgeteer.Core.Data.Repository/BucketRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public IQueryable<Bucket> AllWithVersions() => DatabaseContext.Bucket

public IQueryable<Bucket> AllWithActivities() => DatabaseContext.Bucket
.Include(i => i.BucketMovements)
.Include(i => i.BudgetedTransactions).ThenInclude(i => i.Transaction)
.Include(i => i.BudgetedTransactions)!.ThenInclude(i => i.Transaction)
.AsNoTracking();

public IQueryable<Bucket> AllWithIncludedEntities() => DatabaseContext.Bucket
Expand All @@ -45,7 +45,7 @@ public IQueryable<Bucket> AllWithIncludedEntities() => DatabaseContext.Bucket
.FirstOrDefault(i => i.Id == id);

public Bucket? ByIdWithTransactions(Guid id) => DatabaseContext.Bucket
.Include(i => i.BudgetedTransactions).ThenInclude(i => i.Transaction)
.Include(i => i.BudgetedTransactions)!.ThenInclude(i => i.Transaction)
.FirstOrDefault(i => i.Id == id);

/*public Bucket? ByIdWithActivities(Guid id) => DatabaseContext.Bucket
Expand Down Expand Up @@ -95,8 +95,8 @@ public int Delete(Guid id)
.Include(i => i.BudgetedTransactions)
.FirstOrDefault(i => i.Id == id);
if (entity == null) throw new Exception($"Bucket with id {id} not found.");
if (entity.BucketMovements.Count != 0) throw new Exception($"Cannot delete a Bucket with BucketMovements assigned to it.");
if (entity.BudgetedTransactions.Count != 0) throw new Exception($"Cannot delete a Bucket with BudgetedTransactions assigned to it.");
if (entity.BucketMovements != null && entity.BucketMovements.Count != 0) throw new Exception($"Cannot delete a Bucket with BucketMovements assigned to it.");
if (entity.BudgetedTransactions != null && entity.BudgetedTransactions.Count != 0) throw new Exception($"Cannot delete a Bucket with BudgetedTransactions assigned to it.");

DatabaseContext.Bucket.Remove(entity);
return DatabaseContext.SaveChanges();
Expand All @@ -116,8 +116,8 @@ public int DeleteRange(IEnumerable<Guid> ids)
.Include(i => i.BudgetedTransactions)
.Where(i => cleansedEntities.Contains(i.Id));
if (!entities.Any()) throw new Exception($"No Buckets found with passed IDs.");
if (entities.Any(i => i.BucketMovements.Count != 0)) throw new Exception($"Cannot delete a Bucket with BucketMovements assigned to it.");
if (entities.Any(i => i.BudgetedTransactions.Count != 0)) throw new Exception($"Cannot delete a Bucket with BudgetedTransactions assigned to it.");
if (entities.Any(i => i.BucketMovements != null && i.BucketMovements.Count != 0)) throw new Exception($"Cannot delete a Bucket with BucketMovements assigned to it.");
if (entities.Any(i => i.BudgetedTransactions != null && i.BudgetedTransactions.Count != 0)) throw new Exception($"Cannot delete a Bucket with BudgetedTransactions assigned to it.");

DatabaseContext.Bucket.RemoveRange(entities);
return DatabaseContext.SaveChanges();
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Core.Data.Services/BucketGroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override void Delete(Guid id)

var entity = bucketGroupRepository.ByIdWithIncludedEntities(id);
if (entity == null) throw new Exception("BucketGroup not found");
if (entity.Buckets.Any()) throw new Exception("BucketGroup with Buckets cannot be deleted");
if (entity.Buckets != null && entity.Buckets.Any()) throw new Exception("BucketGroup with Buckets cannot be deleted");

var oldPosition = entity.Position;
bucketGroupRepository.Delete(id);
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Core.Data.Services/BucketRuleSetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override BucketRuleSet Update(BucketRuleSet entity)
.Where(i => i.BucketRuleSetId == entity.Id)
.ToList()
// Select which of the database IDs are no longer available in entity
.Where(i => entity.MappingRules
.Where(i => entity.MappingRules != null && entity.MappingRules
.All(j => j.Id != i.Id))
.Select(i => i.Id)
.ToList();
Expand Down
22 changes: 11 additions & 11 deletions OpenBudgeteer.Core.Data.Services/BucketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Bucket GetWithLatestVersion(Guid id)
var result = repository.ByIdWithVersions(id);
if (result == null) throw new Exception($"{typeof(Bucket)} not found in database");
result.CurrentVersion = GetLatestVersion(id, DateTime.Now);
result.BucketVersions = result.BucketVersions.OrderByDescending(i => i.Version).ToList();
result.BucketVersions = result.BucketVersions!.OrderByDescending(i => i.Version).ToList();

return result;
}
Expand Down Expand Up @@ -97,10 +97,10 @@ public IEnumerable<Bucket> GetActiveBuckets(DateTime validFrom)
.ToList();
foreach (var bucket in result)
{
bucket.CurrentVersion = bucket.BucketVersions
bucket.CurrentVersion = bucket.BucketVersions!
.OrderByDescending(i => i.ValidFrom)
.ToList()
.First(i => i!.ValidFrom <= validFrom);
.First(i => i.ValidFrom <= validFrom);
}

return result;
Expand Down Expand Up @@ -147,19 +147,19 @@ public BucketFigures GetFigures(Guid bucketId, DateTime yearMonth)
decimal input = 0, output = 0;

// Calculate Balance
var balance = bucketWithTransactions.BudgetedTransactions
var balance = bucketWithTransactions.BudgetedTransactions!
.Where(i => i.Transaction.TransactionDate < yearMonth.AddMonths(1))
.ToList()
.Sum(i => i.Amount);

balance += bucketWithMovements.BucketMovements
balance += bucketWithMovements.BucketMovements!
.Where(i => i.MovementDate < yearMonth.AddMonths(1))
.ToList()
.Sum(i => i.Amount);


// Calculate In & Out
var bucketTransactionsCurrentMonth = bucketWithTransactions.BudgetedTransactions
var bucketTransactionsCurrentMonth = bucketWithTransactions.BudgetedTransactions!
.Where(i =>
i.Transaction.TransactionDate.Year == yearMonth.Year &&
i.Transaction.TransactionDate.Month == yearMonth.Month)
Expand All @@ -173,7 +173,7 @@ public BucketFigures GetFigures(Guid bucketId, DateTime yearMonth)
input += bucketTransaction.Amount;
}

var bucketMovementsCurrentMonth = bucketWithMovements.BucketMovements
var bucketMovementsCurrentMonth = bucketWithMovements.BucketMovements!
.Where(i =>
i.MovementDate.Year == yearMonth.Year &&
i.MovementDate.Month == yearMonth.Month)
Expand Down Expand Up @@ -205,12 +205,12 @@ public decimal GetBalance(Guid bucketId, DateTime yearMonth)
var bucketWithTransactions = repository.ByIdWithTransactions(bucketId) ?? throw new Exception("Bucket not found.");
var bucketWithMovements = repository.ByIdWithMovements(bucketId) ?? throw new Exception("Bucket not found.");

var result = bucketWithTransactions.BudgetedTransactions
var result = bucketWithTransactions.BudgetedTransactions!
.Where(i => i.Transaction.TransactionDate < yearMonth.AddMonths(1))
.ToList()
.Sum(i => i.Amount);

result += bucketWithMovements.BucketMovements
result += bucketWithMovements.BucketMovements!
.Where(i => i.MovementDate < yearMonth.AddMonths(1))
.ToList()
.Sum(i => i.Amount);
Expand All @@ -235,7 +235,7 @@ public BucketFigures GetInAndOut(Guid bucketId, DateTime yearMonth)

decimal input = 0, output = 0;

var bucketTransactionsCurrentMonth = bucketWithTransactions.BudgetedTransactions
var bucketTransactionsCurrentMonth = bucketWithTransactions.BudgetedTransactions!
.Where(i =>
i.Transaction.TransactionDate.Year == yearMonth.Year &&
i.Transaction.TransactionDate.Month == yearMonth.Month)
Expand All @@ -249,7 +249,7 @@ public BucketFigures GetInAndOut(Guid bucketId, DateTime yearMonth)
input += bucketTransaction.Amount;
}

var bucketMovementsCurrentMonth = bucketWithMovements.BucketMovements
var bucketMovementsCurrentMonth = bucketWithMovements.BucketMovements!
.Where(i =>
i.MovementDate.Year == yearMonth.Year &&
i.MovementDate.Month == yearMonth.Month)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ protected RuleSetViewModel(IServiceManager serviceManager, IEnumerable<Bucket> a
_targetBucketName = bucketRuleSet.TargetBucket.Name ?? string.Empty;
_targetBucketColorCode = bucketRuleSet.TargetBucket.ColorCode ?? string.Empty;
_targetBucketTextColorCode = bucketRuleSet.TargetBucket.TextColorCode ?? string.Empty;
foreach (var mappingRule in bucketRuleSet.MappingRules)

if (bucketRuleSet.MappingRules != null)
{
MappingRules.Add(new MappingRuleViewModel(serviceManager, mappingRule));
foreach (var mappingRule in bucketRuleSet.MappingRules)
{
MappingRules.Add(new MappingRuleViewModel(serviceManager, mappingRule));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual async Task<ViewModelOperationResult> LoadDataAsync(bool excludeIn

var bucketItemTasks = new List<Task<BucketViewModel>>();

foreach (var bucket in bucketGroup.Buckets.OrderBy(i => i.Name))
foreach (var bucket in bucketGroup.Buckets!.OrderBy(i => i.Name))
{
if (excludeInactive && bucket.IsInactive) continue; // Skip as inactive Buckets should be excluded
if (bucket.ValidFrom > YearMonthViewModel.CurrentMonth) continue; // Bucket not yet active for selected month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected async Task<List<MonthlyBucketExpensesReportResult>> LoadMonthExpensesB
i.Id != Guid.Parse("00000000-0000-0000-0000-000000000002")))
{
// Check on right Bucket Type
var latestVersion = bucket.BucketVersions
var latestVersion = bucket.BucketVersions!
.OrderByDescending(i => i.Version)
.First();
if (latestVersion.BucketType != 2) continue;
Expand Down

0 comments on commit 1e7f079

Please sign in to comment.