Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CodAffection committed Jul 25, 2022
0 parents commit 471da71
Show file tree
Hide file tree
Showing 383 changed files with 91,436 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
dotnet_diagnostic.CS8618.severity = silent
Binary file added .vs/Expense Tracker/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file added .vs/Expense Tracker/v17/.futdcache.v1
Binary file not shown.
Binary file added .vs/Expense Tracker/v17/.suo
Binary file not shown.
30 changes: 30 additions & 0 deletions Expense Tracker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32328.378
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Expense Tracker", "Expense Tracker\Expense Tracker.csproj", "{0B8E3BF2-A3D7-4339-94C9-B369DD9D8388}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BD793830-9C17-42CB-86DC-74BD64B279EB}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0B8E3BF2-A3D7-4339-94C9-B369DD9D8388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B8E3BF2-A3D7-4339-94C9-B369DD9D8388}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B8E3BF2-A3D7-4339-94C9-B369DD9D8388}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B8E3BF2-A3D7-4339-94C9-B369DD9D8388}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {42430D7C-0C20-4BC5-B7C5-FEA126B6AAEE}
EndGlobalSection
EndGlobal
80 changes: 80 additions & 0 deletions Expense Tracker/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Expense_Tracker.Models;

namespace Expense_Tracker.Controllers
{
public class CategoryController : Controller
{
private readonly ApplicationDbContext _context;

public CategoryController(ApplicationDbContext context)
{
_context = context;
}

// GET: Category
public async Task<IActionResult> Index()
{
return _context.Categories != null ?
View(await _context.Categories.ToListAsync()) :
Problem("Entity set 'ApplicationDbContext.Categories' is null.");
}


// GET: Category/AddOrEdit
public IActionResult AddOrEdit(int id = 0)
{
if (id == 0)
return View(new Category());
else
return View(_context.Categories.Find(id));

}

// POST: Category/AddOrEdit
// To protect from overposting attacks, enable the specific properties you want to bind to.
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddOrEdit([Bind("CategoryId,Title,Icon,Type")] Category category)
{
if (ModelState.IsValid)
{
if (category.CategoryId == 0)
_context.Add(category);
else
_context.Update(category);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(category);
}


// POST: Category/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
if (_context.Categories == null)
{
return Problem("Entity set 'ApplicationDbContext.Categories' is null.");
}
var category = await _context.Categories.FindAsync(id);
if (category != null)
{
_context.Categories.Remove(category);
}

await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

}
}
119 changes: 119 additions & 0 deletions Expense Tracker/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using Expense_Tracker.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Globalization;

namespace Expense_Tracker.Controllers
{
public class DashboardController : Controller
{

private readonly ApplicationDbContext _context;

public DashboardController(ApplicationDbContext context)
{
_context = context;
}

public async Task<ActionResult> Index()
{
//Last 7 Days
DateTime StartDate = DateTime.Today.AddDays(-6);
DateTime EndDate = DateTime.Today;

List<Transaction> SelectedTransactions = await _context.Transactions
.Include(x => x.Category)
.Where(y => y.Date >= StartDate && y.Date <= EndDate)
.ToListAsync();

//Total Income
int TotalIncome = SelectedTransactions
.Where(i => i.Category.Type == "Income")
.Sum(j => j.Amount);
ViewBag.TotalIncome = TotalIncome.ToString("C0");

//Total Expense
int TotalExpense = SelectedTransactions
.Where(i => i.Category.Type == "Expense")
.Sum(j => j.Amount);
ViewBag.TotalExpense = TotalExpense.ToString("C0");

//Balance
int Balance = TotalIncome - TotalExpense;
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
culture.NumberFormat.CurrencyNegativePattern = 1;
ViewBag.Balance = String.Format(culture, "{0:C0}", Balance);

//Doughnut Chart - Expense By Category
ViewBag.DoughnutChartData = SelectedTransactions
.Where(i => i.Category.Type == "Expense")
.GroupBy(j => j.Category.CategoryId)
.Select(k => new
{
categoryTitleWithIcon = k.First().Category.Icon + " " + k.First().Category.Title,
amount = k.Sum(j => j.Amount),
formattedAmount = k.Sum(j => j.Amount).ToString("C0"),
})
.OrderByDescending(l => l.amount)
.ToList();

//Spline Chart - Income vs Expense

//Income
List<SplineChartData> IncomeSummary = SelectedTransactions
.Where(i => i.Category.Type == "Income")
.GroupBy(j => j.Date)
.Select(k => new SplineChartData()
{
day = k.First().Date.ToString("dd-MMM"),
income = k.Sum(l => l.Amount)
})
.ToList();

//Expense
List<SplineChartData> ExpenseSummary = SelectedTransactions
.Where(i => i.Category.Type == "Expense")
.GroupBy(j => j.Date)
.Select(k => new SplineChartData()
{
day = k.First().Date.ToString("dd-MMM"),
expense = k.Sum(l => l.Amount)
})
.ToList();

//Combine Income & Expense
string[] Last7Days = Enumerable.Range(0, 7)
.Select(i => StartDate.AddDays(i).ToString("dd-MMM"))
.ToArray();

ViewBag.SplineChartData = from day in Last7Days
join income in IncomeSummary on day equals income.day into dayIncomeJoined
from income in dayIncomeJoined.DefaultIfEmpty()
join expense in ExpenseSummary on day equals expense.day into expenseJoined
from expense in expenseJoined.DefaultIfEmpty()
select new
{
day = day,
income = income == null ? 0 : income.income,
expense = expense == null ? 0 : expense.expense,
};
//Recent Transactions
ViewBag.RecentTransactions = await _context.Transactions
.Include(i => i.Category)
.OrderByDescending(j => j.Date)
.Take(5)
.ToListAsync();


return View();
}
}

public class SplineChartData
{
public string day;
public int income;
public int expense;

}
}
32 changes: 32 additions & 0 deletions Expense Tracker/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Expense_Tracker.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace Expense_Tracker.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
87 changes: 87 additions & 0 deletions Expense Tracker/Controllers/TransactionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Expense_Tracker.Models;

namespace Expense_Tracker.Controllers
{
public class TransactionController : Controller
{
private readonly ApplicationDbContext _context;

public TransactionController(ApplicationDbContext context)
{
_context = context;
}

// GET: Transaction
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.Transactions.Include(t => t.Category);
return View(await applicationDbContext.ToListAsync());
}

// GET: Transaction/AddOrEdit
public IActionResult AddOrEdit(int id = 0)
{
PopulateCategories();
if (id == 0)
return View(new Transaction());
else
return View(_context.Transactions.Find(id));
}

// POST: Transaction/AddOrEdit
// To protect from overposting attacks, enable the specific properties you want to bind to.
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddOrEdit([Bind("TransactionId,CategoryId,Amount,Note,Date")] Transaction transaction)
{
if (ModelState.IsValid)
{
if (transaction.TransactionId == 0)
_context.Add(transaction);
else
_context.Update(transaction);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
PopulateCategories();
return View(transaction);
}

// POST: Transaction/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
if (_context.Transactions == null)
{
return Problem("Entity set 'ApplicationDbContext.Transactions' is null.");
}
var transaction = await _context.Transactions.FindAsync(id);
if (transaction != null)
{
_context.Transactions.Remove(transaction);
}

await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}


[NonAction]
public void PopulateCategories()
{
var CategoryCollection = _context.Categories.ToList();
Category DefaultCategory = new Category() { CategoryId = 0, Title = "Choose a Category" };
CategoryCollection.Insert(0, DefaultCategory);
ViewBag.Categories = CategoryCollection;
}
}
}
26 changes: 26 additions & 0 deletions Expense Tracker/Expense Tracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Expense_Tracker</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="20.1.0.58" />
</ItemGroup>

</Project>
Loading

0 comments on commit 471da71

Please sign in to comment.