.
This commit is contained in:
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.2.32616.157
|
VisualStudioVersion = 17.2.32616.157
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nevyn", "Nevyn\Nevyn.csproj", "{423CD237-7404-4355-868F-CE5861835258}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aberwyn", "Aberwyn\Aberwyn.csproj", "{F5586986-B726-4E05-B31B-2E24CA5B2B89}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aberwyn", "Aberwyn\Aberwyn.csproj", "{F5586986-B726-4E05-B31B-2E24CA5B2B89}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
5
Aberwyn/.config/dotnet-tools.json
Normal file
5
Aberwyn/.config/dotnet-tools.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {}
|
||||||
|
}
|
||||||
@@ -8,6 +8,14 @@
|
|||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="NewFolder\**" />
|
||||||
|
<Content Remove="NewFolder\**" />
|
||||||
|
<EmbeddedResource Remove="NewFolder\**" />
|
||||||
|
<None Remove="NewFolder\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AngularJS.Core" Version="1.8.2" />
|
<PackageReference Include="AngularJS.Core" Version="1.8.2" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.67" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.67" />
|
||||||
@@ -21,9 +29,4 @@
|
|||||||
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.5" />
|
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="NewFolder1\" />
|
|
||||||
<Folder Include="NewFolder\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN mkdir -p /app/build && chmod -R 777 /app/build
|
||||||
|
|
||||||
# Leave the ports exposed to allow Unraid to configure them
|
# Leave the ports exposed to allow Unraid to configure them
|
||||||
EXPOSE 80 443
|
EXPOSE 80 443
|
||||||
|
|
||||||
@@ -10,12 +12,17 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
|||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Copy the .csproj and restore dependencies
|
# Copy the .csproj and restore dependencies
|
||||||
COPY Aberwyn.csproj ./
|
COPY Aberwyn/Aberwyn.csproj ./
|
||||||
RUN dotnet restore
|
RUN dotnet restore
|
||||||
|
|
||||||
|
#COPY Aberwyn/Aberwyn.csproj ./Aberwyn/
|
||||||
|
#WORKDIR /src/Aberwyn
|
||||||
|
#RUN dotnet restore
|
||||||
|
|
||||||
|
|
||||||
# Copy everything else and build the app
|
# Copy everything else and build the app
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN dotnet build Aberwyn.csproj -c Release -o /app/build
|
RUN dotnet build Aberwyn.csproj -c Release -o /app/build/
|
||||||
|
|
||||||
# Publish the app to the /app/publish folder
|
# Publish the app to the /app/publish folder
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 1,
|
|
||||||
"isRoot": true,
|
|
||||||
"tools": {
|
|
||||||
"microsoft.dotnet-msidentity": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"commands": [
|
|
||||||
"dotnet-msidentity"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace Nevyn.Classes
|
|
||||||
{
|
|
||||||
public class Mysql
|
|
||||||
{
|
|
||||||
private MySqlConnection connection;
|
|
||||||
private string server;
|
|
||||||
private string database;
|
|
||||||
private string uid;
|
|
||||||
private string password;
|
|
||||||
|
|
||||||
//Constructor
|
|
||||||
public Mysql()
|
|
||||||
{
|
|
||||||
Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Initialize values
|
|
||||||
private void Initialize()
|
|
||||||
{
|
|
||||||
server = "192.168.1.108";
|
|
||||||
database = "Nevyn";
|
|
||||||
uid = "nevyn";
|
|
||||||
password = "";
|
|
||||||
string connectionString;
|
|
||||||
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
|
|
||||||
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
|
|
||||||
|
|
||||||
connection = new MySqlConnection(connectionString);
|
|
||||||
}
|
|
||||||
//open connection to database
|
|
||||||
public bool OpenConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (connection.State != System.Data.ConnectionState.Open)
|
|
||||||
connection.Open();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (MySqlException ex)
|
|
||||||
{
|
|
||||||
//When handling errors, you can your application's response based
|
|
||||||
//on the error number.
|
|
||||||
//The two most common error numbers when connecting are as follows:
|
|
||||||
//0: Cannot connect to server.
|
|
||||||
//1045: Invalid user name and/or password.
|
|
||||||
switch (ex.Number)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Console.Write("Cannot connect to server. Contact administrator");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1045:
|
|
||||||
Console.Write("Invalid username/password, please try again");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Close connection
|
|
||||||
public bool CloseConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (MySqlException ex)
|
|
||||||
{
|
|
||||||
Console.Write(ex.Message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Models.Wallet SelectWallet()
|
|
||||||
{
|
|
||||||
string query = "SELECT * FROM tblWallet";
|
|
||||||
|
|
||||||
//Create a list to store the result
|
|
||||||
Models.Wallet wallet = new Models.Wallet();
|
|
||||||
|
|
||||||
//Open connection
|
|
||||||
if (this.OpenConnection() == true)
|
|
||||||
{
|
|
||||||
//Create Command
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, connection);
|
|
||||||
//Create a data reader and Execute the command
|
|
||||||
MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
//Read the data and store them in the list
|
|
||||||
while (dataReader.Read())
|
|
||||||
{
|
|
||||||
wallet.Id = (int)dataReader["idtblWallet"];
|
|
||||||
wallet.Kort = (int)dataReader["Kort"];
|
|
||||||
wallet.Buffert = (int)dataReader["Buffert"];
|
|
||||||
wallet.Spara = (int)dataReader["Spara"];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//close Data Reader
|
|
||||||
dataReader.Close();
|
|
||||||
|
|
||||||
//close Connection
|
|
||||||
this.CloseConnection();
|
|
||||||
|
|
||||||
//return list to be displayed
|
|
||||||
return wallet;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return wallet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Models.BudgetItem> getBudgetItems(int ID)
|
|
||||||
{
|
|
||||||
string query = "SELECT * FROM tblBudgetItems WHERE category='" + ID + "'";
|
|
||||||
|
|
||||||
//Create a list to store the result
|
|
||||||
List<Models.BudgetItem> budgetItems = new List<Models.BudgetItem>();
|
|
||||||
|
|
||||||
//Open connection
|
|
||||||
if (this.OpenConnection() == true)
|
|
||||||
{
|
|
||||||
//Create Command
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, connection);
|
|
||||||
//Create a data reader and Execute the command
|
|
||||||
MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
//Read the data and store them in the list
|
|
||||||
while (dataReader.Read())
|
|
||||||
{
|
|
||||||
Models.BudgetItem item = new Models.BudgetItem();
|
|
||||||
item.ID = (int)dataReader["idtblBudgetItems"];
|
|
||||||
item.Name = (string)dataReader["Name"];
|
|
||||||
item.Amount = (int)dataReader["Amount"];
|
|
||||||
item.Description = (string)dataReader["Description"];
|
|
||||||
item.Month = (int)dataReader["Month"];
|
|
||||||
item.Year = (int)dataReader["Year"];
|
|
||||||
//item.User = (int)dataReader["UserID"];
|
|
||||||
|
|
||||||
budgetItems.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
//close Data Reader
|
|
||||||
dataReader.Close();
|
|
||||||
|
|
||||||
//close Connection
|
|
||||||
//this.CloseConnection();
|
|
||||||
|
|
||||||
//return list to be displayed
|
|
||||||
return budgetItems;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return budgetItems;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Models.Category> getBudgetCategories()
|
|
||||||
{
|
|
||||||
string query = "SELECT * FROM tblCategories";
|
|
||||||
|
|
||||||
//Create a list to store the result
|
|
||||||
List<Models.Category> categoryList = new List<Models.Category>();
|
|
||||||
|
|
||||||
//Open connection
|
|
||||||
if (this.OpenConnection() == true)
|
|
||||||
{
|
|
||||||
//Create Command
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, connection);
|
|
||||||
//Create a data reader and Execute the command
|
|
||||||
MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
||||||
|
|
||||||
//Read the data and store them in the list
|
|
||||||
while (dataReader.Read())
|
|
||||||
{
|
|
||||||
Models.Category category = new Models.Category();
|
|
||||||
category.ID = (int)dataReader["idtblCategories"];
|
|
||||||
category.Name = (string)dataReader["Name"];
|
|
||||||
category.parent = (int)dataReader["parent"];
|
|
||||||
categoryList.Add(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
//close Data Reader
|
|
||||||
dataReader.Close();
|
|
||||||
|
|
||||||
for (var i = 0; i < categoryList.Count(); i++)
|
|
||||||
{
|
|
||||||
categoryList[i].Items = this.getBudgetItems(categoryList[i].ID);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//close Connection
|
|
||||||
this.CloseConnection();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//return list to be displayed
|
|
||||||
return categoryList;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return categoryList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Nevyn.Models;
|
|
||||||
using Nevyn.Classes;
|
|
||||||
|
|
||||||
namespace Nevyn.Controllers
|
|
||||||
{
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
public class BudgetController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly BudgetContext _context;
|
|
||||||
public BudgetController(BudgetContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/ShoppingLists
|
|
||||||
[HttpGet]
|
|
||||||
public async Task<ActionResult<BudgetDTO>> GetBudget()
|
|
||||||
{
|
|
||||||
//Budget budget = await _context.UpdateBudget.FindAsync(1);
|
|
||||||
|
|
||||||
Budget budget = new Budget();
|
|
||||||
budget.updateFromDatabase();
|
|
||||||
//_context.UpdateBudget.Add(budget);
|
|
||||||
//await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
|
|
||||||
return ItemToDTO(budget);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static BudgetDTO ItemToDTO(Budget budget) =>
|
|
||||||
new BudgetDTO
|
|
||||||
{
|
|
||||||
|
|
||||||
Categories = budget.Categories,
|
|
||||||
Debug = "There is days left",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Nevyn.Models;
|
|
||||||
using Nevyn.Classes;
|
|
||||||
|
|
||||||
namespace Nevyn.Controllers
|
|
||||||
{
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
public class MoneyController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly MoneyContext _context;
|
|
||||||
public MoneyController(MoneyContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/ShoppingLists
|
|
||||||
[HttpGet]
|
|
||||||
public async Task<ActionResult<WalletDTO>> GetWallet()
|
|
||||||
{
|
|
||||||
Wallet wallet = await _context.UpdateWallet.FindAsync(1);
|
|
||||||
|
|
||||||
if (wallet == null)
|
|
||||||
{
|
|
||||||
wallet = new Wallet();
|
|
||||||
wallet.updateFromDatabase();
|
|
||||||
_context.UpdateWallet.Add(wallet);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
return ItemToDTO(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/ShoppingLists/5
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
public async Task<ActionResult<WalletDTO>> GetWallet(long id)
|
|
||||||
{
|
|
||||||
var wallet = await _context.UpdateWallet.FindAsync(id);
|
|
||||||
|
|
||||||
if (wallet == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ItemToDTO(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUT: api/ShoppingLists/5
|
|
||||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
||||||
[HttpPut]
|
|
||||||
public async Task<IActionResult> PutWallet(long id, Wallet wallet)
|
|
||||||
{
|
|
||||||
|
|
||||||
var currentWallet = await _context.UpdateWallet.FindAsync(wallet.Id);
|
|
||||||
if (currentWallet == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
currentWallet.Kort = wallet.Kort;
|
|
||||||
currentWallet.Buffert = wallet.Buffert;
|
|
||||||
currentWallet.Fonder = wallet.Fonder;
|
|
||||||
currentWallet.Spara = wallet.Spara;
|
|
||||||
|
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: api/ShoppingLists
|
|
||||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
||||||
[HttpPost]
|
|
||||||
public async Task<ActionResult<WalletDTO>> PostWallet(Wallet inputWallet)
|
|
||||||
{
|
|
||||||
|
|
||||||
var wallet = new Wallet
|
|
||||||
{
|
|
||||||
Buffert = inputWallet.Buffert,
|
|
||||||
Fonder = inputWallet.Fonder,
|
|
||||||
Kort = inputWallet.Kort,
|
|
||||||
Spara = inputWallet.Spara,
|
|
||||||
};
|
|
||||||
|
|
||||||
_context.UpdateWallet.Add(wallet);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return CreatedAtAction(
|
|
||||||
nameof(GetWallet),
|
|
||||||
new { id = wallet.Id },
|
|
||||||
ItemToDTO(wallet));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static WalletDTO ItemToDTO(Wallet wallet) =>
|
|
||||||
new WalletDTO
|
|
||||||
{
|
|
||||||
Kort = wallet.Kort,
|
|
||||||
TotalAmount = wallet.TotalAmount,
|
|
||||||
AmountLeftPerDay = wallet.MoneyUntilSalary,
|
|
||||||
Debug = "There is " + wallet.DaysLeftUntilSalary + " days left",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Nevyn.Models;
|
|
||||||
|
|
||||||
namespace Nevyn.Controllers
|
|
||||||
{
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
public class ShoppingListsController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly ShoppingContext _context;
|
|
||||||
|
|
||||||
public ShoppingListsController(ShoppingContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/ShoppingLists
|
|
||||||
[HttpGet]
|
|
||||||
public async Task<ActionResult<IEnumerable<ShoppingListDTO>>> GetUpdateShopping()
|
|
||||||
{
|
|
||||||
return await _context.UpdateShopping.Select(x => ItemToDTO(x)).ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/ShoppingLists/5
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
public async Task<ActionResult<ShoppingListDTO>> GetShoppingList(long id)
|
|
||||||
{
|
|
||||||
var shoppingList = await _context.UpdateShopping.FindAsync(id);
|
|
||||||
|
|
||||||
if (shoppingList == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ItemToDTO(shoppingList);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUT: api/ShoppingLists/5
|
|
||||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
||||||
[HttpPut("{id}")]
|
|
||||||
public async Task<IActionResult> PutShoppingList(long id, ShoppingListDTO shoppingListDTO)
|
|
||||||
{
|
|
||||||
if (id != shoppingListDTO.Id)
|
|
||||||
{
|
|
||||||
return BadRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
//_context.Entry(shoppingList).State = EntityState.Modified;
|
|
||||||
|
|
||||||
var shoppingList = await _context.UpdateShopping.FindAsync(id);
|
|
||||||
if (shoppingList == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
shoppingList.Name = shoppingListDTO.Name;
|
|
||||||
shoppingList.IsComplete = shoppingListDTO.IsComplete;
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
catch (DbUpdateConcurrencyException) when (!ShoppingListExists(id))
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: api/ShoppingLists
|
|
||||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
||||||
[HttpPost]
|
|
||||||
public async Task<ActionResult<ShoppingListDTO>> PostShoppingList(ShoppingListDTO shoppingListDTO)
|
|
||||||
{
|
|
||||||
|
|
||||||
var shoppingList = new ShoppingList
|
|
||||||
{
|
|
||||||
IsComplete = shoppingListDTO.IsComplete,
|
|
||||||
Name = shoppingListDTO.Name
|
|
||||||
};
|
|
||||||
|
|
||||||
_context.UpdateShopping.Add(shoppingList);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return CreatedAtAction(
|
|
||||||
nameof(GetShoppingList),
|
|
||||||
new { id = shoppingList.Id },
|
|
||||||
ItemToDTO(shoppingList));
|
|
||||||
}
|
|
||||||
|
|
||||||
// DELETE: api/ShoppingLists/5
|
|
||||||
[HttpDelete("{id}")]
|
|
||||||
public async Task<IActionResult> DeleteShoppingList(long id)
|
|
||||||
{
|
|
||||||
var shoppingList = await _context.UpdateShopping.FindAsync(id);
|
|
||||||
if (shoppingList == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
_context.UpdateShopping.Remove(shoppingList);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ShoppingListExists(long id)
|
|
||||||
{
|
|
||||||
return _context.UpdateShopping.Any(e => e.Id == id);
|
|
||||||
}
|
|
||||||
private static ShoppingListDTO ItemToDTO(ShoppingList shoppingList) =>
|
|
||||||
new ShoppingListDTO
|
|
||||||
{
|
|
||||||
Id = shoppingList.Id,
|
|
||||||
Name = shoppingList.Name,
|
|
||||||
IsComplete = shoppingList.IsComplete
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
|
||||||
WORKDIR /app
|
|
||||||
EXPOSE 80
|
|
||||||
EXPOSE 443
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
|
||||||
WORKDIR /src
|
|
||||||
COPY ["Nevyn/Nevyn.csproj", "Nevyn/"]
|
|
||||||
RUN dotnet restore "Nevyn/Nevyn.csproj"
|
|
||||||
COPY . .
|
|
||||||
WORKDIR "/src/Nevyn"
|
|
||||||
RUN dotnet build "Nevyn.csproj" -c Release -o /app/build
|
|
||||||
|
|
||||||
FROM build AS publish
|
|
||||||
RUN dotnet publish "Nevyn.csproj" -c Release -o /app/publish
|
|
||||||
|
|
||||||
FROM base AS final
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
ENTRYPOINT ["dotnet", "Nevyn.dll"]
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class Budget
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public List<Category> Categories { get; set; }
|
|
||||||
public Budget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//public void getBudgetFromSQL()
|
|
||||||
//this = Classes.Mysql.getBudget();
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void updateFromDatabase()
|
|
||||||
{
|
|
||||||
Classes.Mysql mysql = new Classes.Mysql();
|
|
||||||
|
|
||||||
this.Categories = mysql.getBudgetCategories();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Category
|
|
||||||
{
|
|
||||||
public int ID { get; set; }
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public int parent { get; set; }
|
|
||||||
public List<BudgetItem> Items { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BudgetItem
|
|
||||||
{
|
|
||||||
public int ID { get; set; }
|
|
||||||
public string? Name { get; set; }
|
|
||||||
//public user User { get; set; }
|
|
||||||
public int Amount { get; set; }
|
|
||||||
public string? Description { get; set; }
|
|
||||||
public bool Recurring { get; set; }
|
|
||||||
public int Month { get; set; }
|
|
||||||
public int Year { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class BudgetDTO
|
|
||||||
{
|
|
||||||
public List<Category> Categories { get; set; }
|
|
||||||
public string Debug { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class BudgetContext : DbContext
|
|
||||||
{
|
|
||||||
public BudgetContext(DbContextOptions<BudgetContext> options) : base(options)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbSet<Budget> UpdateBudget { get; set; } = null!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
using System;
|
|
||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class Wallet
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public int TotalAmount
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Kort + this.Buffert + this.Spara + this.Fonder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int Kort { get; set; }
|
|
||||||
public int Buffert { get; set; }
|
|
||||||
public int Spara { get; set; }
|
|
||||||
public int Fonder { get; set; }
|
|
||||||
|
|
||||||
public int MoneyUntilSalary {
|
|
||||||
get
|
|
||||||
{
|
|
||||||
DateTime payDay = SalaryCalculator.CalculatePayDay(DateTime.Now);
|
|
||||||
this.DaysLeftUntilSalary = (payDay - DateTime.Now).Days;
|
|
||||||
return this.Kort / this.DaysLeftUntilSalary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int DaysLeftUntilSalary { get; set; }
|
|
||||||
|
|
||||||
public class SalaryCalculator
|
|
||||||
{
|
|
||||||
public static DateTime CalculatePayDay(DateTime date)
|
|
||||||
{
|
|
||||||
// Get the 25th of the current month
|
|
||||||
var payDay = new DateTime(date.Year, date.Month, 25);
|
|
||||||
|
|
||||||
// If the 25th is on a weekend, get the previous Friday
|
|
||||||
if (payDay.DayOfWeek == DayOfWeek.Saturday)
|
|
||||||
{
|
|
||||||
payDay = payDay.AddDays(-1);
|
|
||||||
}
|
|
||||||
else if (payDay.DayOfWeek == DayOfWeek.Sunday)
|
|
||||||
{
|
|
||||||
payDay = payDay.AddDays(-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return payDay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateFromDatabase()
|
|
||||||
{
|
|
||||||
Classes.Mysql mysql = new Classes.Mysql();
|
|
||||||
|
|
||||||
Wallet dbWallet = mysql.SelectWallet();
|
|
||||||
this.Kort = dbWallet.Kort;
|
|
||||||
this.Spara = dbWallet.Spara;
|
|
||||||
this.Buffert = dbWallet.Buffert;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WalletDTO
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public int TotalAmount { get; set; }
|
|
||||||
public int AmountLeftPerDay { get; set; }
|
|
||||||
public int Kort { get; set; }
|
|
||||||
public string Debug { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class MoneyContext : DbContext
|
|
||||||
{
|
|
||||||
public MoneyContext(DbContextOptions<MoneyContext> options) : base(options)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbSet<Wallet> UpdateWallet { get; set; } = null!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class ShoppingContext : DbContext
|
|
||||||
{
|
|
||||||
public ShoppingContext(DbContextOptions<ShoppingContext> options) : base(options)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbSet<ShoppingList> UpdateShopping { get; set; } = null!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
namespace Nevyn.Models
|
|
||||||
{
|
|
||||||
public class ShoppingList
|
|
||||||
{
|
|
||||||
public long Id { get; set; }
|
|
||||||
public int Amount { get; set; }
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public bool IsComplete { get; set; }
|
|
||||||
public string? Secret { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
public class ShoppingListDTO
|
|
||||||
{
|
|
||||||
public long Id { get; set; }
|
|
||||||
public int Amount { get; set; }
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public bool IsComplete { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<UserSecretsId>aspnet-Nevyn-7C7F87FA-EADD-461B-8418-8C03C2EF8DB3</UserSecretsId>
|
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.12" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.12">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.Identity.Web" Version="1.16.0" />
|
|
||||||
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.16.0" />
|
|
||||||
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.16.0" />
|
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
|
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.11" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
|
||||||
<PackageReference Include="MySql.Data" Version="8.0.32" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="MySql.Data" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
using Microsoft.Identity.Web;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Nevyn.Models;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
|
|
||||||
// Add services to the container.
|
|
||||||
//builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddDbContext<ShoppingContext>(opt =>
|
|
||||||
opt.UseInMemoryDatabase("ShoppingList"));
|
|
||||||
builder.Services.AddDbContext<MoneyContext>(opt =>
|
|
||||||
opt.UseInMemoryDatabase("Wallet"));
|
|
||||||
builder.Services.AddDbContext<BudgetContext>(opt =>
|
|
||||||
opt.UseInMemoryDatabase("Budget"));
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
//if (app.Environment.IsDevelopment())
|
|
||||||
//{
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//app.UseHttpsRedirection();
|
|
||||||
|
|
||||||
//app.UseAuthentication();
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
app.MapControllers();
|
|
||||||
|
|
||||||
app.Run();
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:8080",
|
|
||||||
"sslPort": 44397
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"Nevyn": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "http://localhost:8080",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Docker": {
|
|
||||||
"commandName": "Docker",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
|
||||||
"environmentVariables": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"dependencies": {
|
|
||||||
"identityapp1": {
|
|
||||||
"type": "identityapp",
|
|
||||||
"connectionId": "AzureAD:ClientSecret",
|
|
||||||
"dynamicId": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"dependencies": {
|
|
||||||
"identityapp1": {
|
|
||||||
"secretStore": "LocalSecretsFile",
|
|
||||||
"type": "identityapp.secretStore",
|
|
||||||
"connectionId": "AzureAD:ClientSecret",
|
|
||||||
"dynamicId": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user