Initial commit
Initial commit til Git. V2 er deployed
This commit is contained in:
12
PointOfSale/Pos.Ui/Database/.config/dotnet-tools.json
Normal file
12
PointOfSale/Pos.Ui/Database/.config/dotnet-tools.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "5.0.9",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
16
PointOfSale/Pos.Ui/Database/Database.csproj
Normal file
16
PointOfSale/Pos.Ui/Database/Database.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
60
PointOfSale/Pos.Ui/Database/LoadConfig.cs
Normal file
60
PointOfSale/Pos.Ui/Database/LoadConfig.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Pos
|
||||
{
|
||||
public class LoadConfig
|
||||
{
|
||||
private string dir;
|
||||
public LoadConfig()
|
||||
{
|
||||
dir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
}
|
||||
public IConfiguration ByEnvironment()
|
||||
{
|
||||
//Console.Out.WriteLine($"Json path: {dir}");
|
||||
#if DEBUG
|
||||
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(dir)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
return config;
|
||||
|
||||
#else
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(dir)
|
||||
.AddJsonFile("appsettings.Production.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
return config;
|
||||
#endif
|
||||
//Running in a environment that not is supported in this setup
|
||||
throw new Exception("HostingEnvironment is not supported! This config setup only supports Development or Production");
|
||||
}
|
||||
|
||||
public IConfiguration DebugConfiguration()
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(dir)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
return config;
|
||||
}
|
||||
|
||||
public IConfiguration ReleaseConfiguration()
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(dir)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile("appsettings.Production.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
PointOfSale/Pos.Ui/Database/Models/EmployeeEntity.cs
Normal file
20
PointOfSale/Pos.Ui/Database/Models/EmployeeEntity.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("employee")]
|
||||
public class EmployeeEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsArchived { get; set; }
|
||||
public bool IsModified { get; set; }
|
||||
}
|
||||
}
|
||||
21
PointOfSale/Pos.Ui/Database/Models/PaymentEntity.cs
Normal file
21
PointOfSale/Pos.Ui/Database/Models/PaymentEntity.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("payment")]
|
||||
public class PaymentEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public int SaleId { get; set; }
|
||||
public decimal Amount { get; set;}
|
||||
public string Type { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
22
PointOfSale/Pos.Ui/Database/Models/ProductEntity.cs
Normal file
22
PointOfSale/Pos.Ui/Database/Models/ProductEntity.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("product")]
|
||||
public class ProductEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool IsArchived { get; set; }
|
||||
public int Index { get; set; }
|
||||
public bool IsModified { get; set; }
|
||||
public int ProductGroupId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ProductGroupId))]
|
||||
public ProductGroupEntity ProductGroup { get; set; }
|
||||
}
|
||||
}
|
||||
22
PointOfSale/Pos.Ui/Database/Models/ProductGroupEntity.cs
Normal file
22
PointOfSale/Pos.Ui/Database/Models/ProductGroupEntity.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("productgroup")]
|
||||
public class ProductGroupEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsArchived { get; set; }
|
||||
public int Index { get; set; }
|
||||
|
||||
public ICollection<ProductEntity> Products { get; set; }
|
||||
}
|
||||
}
|
||||
20
PointOfSale/Pos.Ui/Database/Models/SaleEntity.cs
Normal file
20
PointOfSale/Pos.Ui/Database/Models/SaleEntity.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("sale")]
|
||||
public class SaleEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
public bool IsModified { get; set; }
|
||||
}
|
||||
}
|
||||
22
PointOfSale/Pos.Ui/Database/Models/SaleLineEntity.cs
Normal file
22
PointOfSale/Pos.Ui/Database/Models/SaleLineEntity.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Database.Models
|
||||
{
|
||||
[Table("sale_line")]
|
||||
public class SaleLineEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public int SaleId { get; set; }
|
||||
public string Product { get; set; }
|
||||
public int Pieces { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public decimal Total { get; set; }
|
||||
}
|
||||
}
|
||||
35
PointOfSale/Pos.Ui/Database/PosDbContext.cs
Normal file
35
PointOfSale/Pos.Ui/Database/PosDbContext.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Pos;
|
||||
|
||||
|
||||
namespace Database
|
||||
{
|
||||
public class PosDbContext : DbContext
|
||||
{
|
||||
|
||||
public DbSet<EmployeeEntity> Employee { get; set; }
|
||||
public DbSet<ProductGroupEntity> ProductGroups { get; set; }
|
||||
public DbSet<ProductEntity> Products { get; set; }
|
||||
public DbSet<SaleEntity> Sales { get; set; }
|
||||
public DbSet<SaleLineEntity> SalesLines { get; set; }
|
||||
public DbSet<PaymentEntity> Payment { get; set; }
|
||||
|
||||
protected override void OnConfiguring(
|
||||
DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
LoadConfig l = new LoadConfig();
|
||||
IConfiguration config = l.ByEnvironment();
|
||||
string connectionString = config["MariaSqlServer"].ToString();
|
||||
optionsBuilder
|
||||
.UseMySql(connectionString,ServerVersion.AutoDetect(connectionString))
|
||||
.UseLoggerFactory(LoggerFactory.Create(b => b
|
||||
.AddFilter(level => level >= LogLevel.Information)))
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
PointOfSale/Pos.Ui/Database/Repository/EmployeeRepository.cs
Normal file
62
PointOfSale/Pos.Ui/Database/Repository/EmployeeRepository.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
87
PointOfSale/Pos.Ui/Database/Repository/ProductRepository.cs
Normal file
87
PointOfSale/Pos.Ui/Database/Repository/ProductRepository.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
83
PointOfSale/Pos.Ui/Database/Repository/SaleRepository.cs
Normal file
83
PointOfSale/Pos.Ui/Database/Repository/SaleRepository.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user