Initial commit

Initial commit til Git.
V2 er deployed
This commit is contained in:
2026-06-13 17:31:50 +02:00
parent 9fcd2b145e
commit 41e23b6184
375 changed files with 15956 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Database.Models;
using Microsoft.Extensions.Configuration;
namespace Database.Repository
{
public class EmployeeRepository : IDisposable
{
public void Add(string name)
{
EmployeeEntity employee = new EmployeeEntity();
employee.Name = name;
employee.IsModified = true;
using PosDbContext context = new PosDbContext();
context.Employee.Add(employee);
context.SaveChanges();
}
public EmployeeEntity Get(int employeeId)
{
using PosDbContext context = new PosDbContext();
EmployeeEntity employeeEntity = context.Employee.First(c => c.Id == employeeId);
return employeeEntity;
}
public List<EmployeeEntity> GetAll()
{
using PosDbContext context = new PosDbContext();
List<EmployeeEntity> staffs = context.Employee.Where(c => c.IsArchived == false).ToList();
return staffs;
}
public void Edit(int id, string name)
{
using PosDbContext context = new PosDbContext();
EmployeeEntity employee = context.Employee.Single(c => c.Id == id);
employee.Name = name;
employee.IsModified = true;
context.SaveChanges();
}
public void Delete(int id)
{
using PosDbContext context = new PosDbContext();
EmployeeEntity employee = context.Employee.Single(c => c.Id == id);
employee.IsArchived = true;
employee.IsModified = true;
context.SaveChanges();
}
public void Dispose()
{
}
}
}

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Database.Models;
using Microsoft.EntityFrameworkCore;
namespace Database.Repository
{
public class ProductGroupRepository
{
public List<ProductGroupEntity> GetAll()
{
using PosDbContext context = new PosDbContext();
List<ProductGroupEntity> productGroups = context.ProductGroups
.Include(c => c.Products)
.Where(c => c.IsArchived == false)
.OrderBy(c => c.Index)
.ToList();
return productGroups;
}
public ProductGroupEntity Get(int id)
{
using PosDbContext context = new PosDbContext();
ProductGroupEntity product = context.ProductGroups.Single(c => c.Id == id);
return product;
}
public void Add(string name)
{
ProductGroupEntity productGroup = new ProductGroupEntity();
productGroup.Name = name;
using PosDbContext context = new PosDbContext();
//Get the highest index
ProductGroupEntity highest = context.ProductGroups.OrderByDescending(c => c.Index).Take(1).FirstOrDefault();
if(highest == null)
{
highest = new ProductGroupEntity();
highest.Index = 0;
}
productGroup.Index = highest.Index + 1;
context.ProductGroups.Add(productGroup);
context.SaveChanges();
}
public void Edit(string name, int id)
{
using PosDbContext context = new PosDbContext();
ProductGroupEntity productGroup = context.ProductGroups.Single(c => c.Id == id);
productGroup.Name = name;
context.SaveChanges();
}
public void Archive(int id)
{
using PosDbContext context = new PosDbContext();
ProductGroupEntity productGroup = context.ProductGroups.Single(c => c.Id == id);
productGroup.IsArchived = true;
context.SaveChanges();
}
public void SetIndex(int id, int index)
{
using PosDbContext context = new PosDbContext();
ProductGroupEntity productGroup = context.ProductGroups.Single(c => c.Id == id);
productGroup.Index = index;
context.SaveChanges();
}
public bool Any()
{
using PosDbContext context = new PosDbContext();
bool any = context.ProductGroups.Any();
return any;
}
}
}

View File

@@ -0,0 +1,87 @@
using System.Collections.Generic;
using System.Linq;
using Database.Models;
namespace Database.Repository
{
public class ProductRepository
{
public List<ProductEntity> GetAll()
{
using PosDbContext context = new PosDbContext();
List<ProductEntity> products = context.Products
.Where(c => c.IsArchived == false)
.OrderBy(c => c.Index)
.ToList();
return products;
}
public List<ProductEntity> GetByProductGroup(int id)
{
using PosDbContext context = new PosDbContext();
List<ProductEntity> products = context.Products
.Where(c => c.ProductGroupId == id)
.Where(c => c.IsArchived == false)
.OrderBy(c => c.Index)
.ToList();
return products;
}
public void SetIndex(int id, int index)
{
using PosDbContext context = new PosDbContext();
ProductEntity product = context.Products.Single(c => c.Id == id);
product.Index = index;
product.IsModified = true;
context.SaveChanges();
}
public ProductEntity GetById(int id)
{
using PosDbContext context = new PosDbContext();
ProductEntity product = context.Products.Single(c => c.Id == id);
return product;
}
public void Update(int id, int productGroupId, string name)
{
using PosDbContext context = new PosDbContext();
ProductEntity dbProduct = context.Products.Single(c => c.Id == id);
dbProduct.ProductGroupId = productGroupId;
dbProduct.Name = name;
dbProduct.IsModified = true;
context.SaveChanges();
}
public void Archive(int id)
{
using PosDbContext context = new PosDbContext();
ProductEntity dbProduct = context.Products.Single(c => c.Id == id);
dbProduct.IsArchived = true;
dbProduct.IsModified = true;
context.SaveChanges();
}
public void Add(string name, int productGroupId)
{
ProductEntity product = new ProductEntity();
product.Name = name;
product.ProductGroupId = productGroupId;
using PosDbContext context = new PosDbContext();
//Get the highest index
ProductEntity highest = context.Products.OrderByDescending(c => c.Index).Take(1).FirstOrDefault();
if (highest == null)
{
highest = new ProductEntity();
highest.Index = 0;
}
product.Index = highest.Index + 1;
product.IsModified = true;
context.Products.Add(product);
context.SaveChanges();
}
}
}

View File

@@ -0,0 +1,83 @@
using Database.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Database.Repository
{
public class SaleRepository
{
public SaleEntity New(int employeeId)
{
using PosDbContext context = new PosDbContext();
SaleEntity saleEntity = new SaleEntity();
saleEntity.Time = DateTime.Now;
saleEntity.EmployeeId = employeeId;
saleEntity.IsModified = true;
context.Sales.Add(saleEntity);
context.SaveChanges();
return saleEntity;
}
public SaleLineEntity SaveSaleLine(SaleLineEntity entity)
{
using PosDbContext context = new PosDbContext();
context.SalesLines.Add(entity);
context.SaveChanges();
return entity;
}
public List<SaleLineEntity> GetSaleLineBySaleId(int saleId)
{
using PosDbContext context = new PosDbContext();
List<SaleLineEntity> saleLineEntities = context.SalesLines.Where(c => c.SaleId == saleId).ToList();
return saleLineEntities;
}
public PaymentEntity SavePayment(PaymentEntity entity)
{
using PosDbContext context = new PosDbContext();
context.Payment.Add(entity);
context.SaveChanges();
return entity;
}
public List<PaymentEntity> GetPaymentBySaleId(int saleId)
{
using PosDbContext context = new PosDbContext();
List<PaymentEntity> paymentEntities = context.Payment.Where(c => c.SaleId == saleId).ToList();
return paymentEntities;
}
public SaleEntity GetLatest()
{
using PosDbContext context = new PosDbContext();
SaleEntity saleEntity = context.Sales.OrderByDescending(c => c.Id).Take(1).First();
return saleEntity;
}
public SaleEntity Get(int id)
{
using PosDbContext context = new PosDbContext();
SaleEntity saleEntity = context.Sales.Single(c => c.Id == id);
return saleEntity;
}
public List<SaleEntity> GetByDateRange(DateTime start, DateTime end)
{
using PosDbContext context = new PosDbContext();
List<SaleEntity> saleEntities = context.Sales.Where(c => c.Time.Date >= start.Date && c.Time.Date <= end.Date).OrderByDescending(c => c.Time).ToList();
return saleEntities;
}
public List<SaleEntity> GetByDateRange(DateTime start)
{
using PosDbContext context = new PosDbContext();
List<SaleEntity> saleEntities = context.Sales.Where(c => c.Time.Date == start.Date.Date).OrderByDescending(c => c.Time).ToList();
return saleEntities;
}
}
}