Initial commit
Initial commit til Git. V2 er deployed
This commit is contained in:
7
PointOfSale/Pos.Api/Pos.Api.Database/Class1.cs
Normal file
7
PointOfSale/Pos.Api/Pos.Api.Database/Class1.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Pos.Api.Database
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
162
PointOfSale/Pos.Api/Pos.Api.Database/Data/PosApiContext.cs
Normal file
162
PointOfSale/Pos.Api/Pos.Api.Database/Data/PosApiContext.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pos.Api.Database.Models;
|
||||
|
||||
namespace Pos.Api.Database.Data;
|
||||
|
||||
public partial class PosApiContext : DbContext
|
||||
{
|
||||
public PosApiContext(DbContextOptions<PosApiContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Employee> Employees { get; set; }
|
||||
|
||||
public virtual DbSet<LastUpdate> LastUpdates { get; set; }
|
||||
|
||||
public virtual DbSet<Payment> Payments { get; set; }
|
||||
|
||||
public virtual DbSet<Product> Products { get; set; }
|
||||
|
||||
public virtual DbSet<Productgroup> Productgroups { get; set; }
|
||||
|
||||
public virtual DbSet<Sale> Sales { get; set; }
|
||||
|
||||
public virtual DbSet<SaleLine> SaleLines { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.UseCollation("latin1_swedish_ci")
|
||||
.HasCharSet("latin1");
|
||||
|
||||
modelBuilder.Entity<Employee>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("employee")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnType("int(11)");
|
||||
entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<LastUpdate>(entity =>
|
||||
{
|
||||
entity
|
||||
.HasNoKey()
|
||||
.ToTable("LastUpdate");
|
||||
|
||||
entity.Property(e => e.DateTime).HasColumnType("datetime");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Payment>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("payment")
|
||||
.HasCharSet("armscii8")
|
||||
.UseCollation("armscii8_bin");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Amount).HasPrecision(20, 6);
|
||||
entity.Property(e => e.SaleId).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Type)
|
||||
.IsRequired()
|
||||
.HasColumnType("tinytext");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Product>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("product")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.HasIndex(e => e.ProductGroupId, "FK_Product_Categories");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int(11)");
|
||||
entity.Property(e => e.Description).HasColumnType("mediumtext");
|
||||
entity.Property(e => e.Index).HasColumnType("int(11)");
|
||||
entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasColumnType("tinytext");
|
||||
entity.Property(e => e.Price).HasPrecision(10, 2);
|
||||
entity.Property(e => e.ProductGroupId).HasColumnType("int(11)");
|
||||
|
||||
entity.HasOne(d => d.IdNavigation).WithOne(p => p.Product)
|
||||
.HasForeignKey<Product>(d => d.Id)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("FK_Product_ProductGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Productgroup>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("productgroup")
|
||||
.HasCharSet("utf8mb4")
|
||||
.UseCollation("utf8mb4_general_ci");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Index).HasColumnType("int(11)");
|
||||
entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
|
||||
entity.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasColumnType("tinytext");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Sale>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("sale")
|
||||
.HasCharSet("armscii8")
|
||||
.UseCollation("armscii8_bin");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnType("int(11)");
|
||||
entity.Property(e => e.EmployeeId).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Time).HasColumnType("datetime");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<SaleLine>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity
|
||||
.ToTable("sale_line")
|
||||
.HasCharSet("armscii8")
|
||||
.UseCollation("armscii8_bin");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Pieces).HasColumnType("smallint(6)");
|
||||
entity.Property(e => e.Price).HasPrecision(20, 6);
|
||||
entity.Property(e => e.Product)
|
||||
.IsRequired()
|
||||
.HasColumnType("tinytext");
|
||||
entity.Property(e => e.SaleId).HasColumnType("int(11)");
|
||||
entity.Property(e => e.Total).HasPrecision(20, 6);
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pos.Api.Database.Data
|
||||
{
|
||||
public partial class PosApiContext
|
||||
{
|
||||
|
||||
protected override void OnConfiguring(
|
||||
DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
LoadConfig l = new LoadConfig();
|
||||
IConfiguration config = l.ByEnvironment();
|
||||
string connectionString = config["MySQL"].ToString();
|
||||
optionsBuilder
|
||||
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))
|
||||
.UseLoggerFactory(LoggerFactory.Create(b => b
|
||||
.AddFilter(level => level >= LogLevel.Information)))
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
PointOfSale/Pos.Api/Pos.Api.Database/LoadConfig.cs
Normal file
55
PointOfSale/Pos.Api/Pos.Api.Database/LoadConfig.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Pos.Api.Database
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
PointOfSale/Pos.Api/Pos.Api.Database/Models/Employee.cs
Normal file
15
PointOfSale/Pos.Api/Pos.Api.Database/Models/Employee.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class Employee
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public sbyte IsArchived { get; set; }
|
||||
}
|
||||
11
PointOfSale/Pos.Api/Pos.Api.Database/Models/LastUpdate.cs
Normal file
11
PointOfSale/Pos.Api/Pos.Api.Database/Models/LastUpdate.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class LastUpdate
|
||||
{
|
||||
public DateTime? DateTime { get; set; }
|
||||
}
|
||||
17
PointOfSale/Pos.Api/Pos.Api.Database/Models/Payment.cs
Normal file
17
PointOfSale/Pos.Api/Pos.Api.Database/Models/Payment.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class Payment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int SaleId { get; set; }
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
}
|
||||
25
PointOfSale/Pos.Api/Pos.Api.Database/Models/Product.cs
Normal file
25
PointOfSale/Pos.Api/Pos.Api.Database/Models/Product.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class Product
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public int ProductGroupId { get; set; }
|
||||
|
||||
public sbyte IsArchived { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public virtual Productgroup IdNavigation { get; set; }
|
||||
}
|
||||
19
PointOfSale/Pos.Api/Pos.Api.Database/Models/Productgroup.cs
Normal file
19
PointOfSale/Pos.Api/Pos.Api.Database/Models/Productgroup.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class Productgroup
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public sbyte IsArchived { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public virtual Product Product { get; set; }
|
||||
}
|
||||
15
PointOfSale/Pos.Api/Pos.Api.Database/Models/Sale.cs
Normal file
15
PointOfSale/Pos.Api/Pos.Api.Database/Models/Sale.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class Sale
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime Time { get; set; }
|
||||
|
||||
public int EmployeeId { get; set; }
|
||||
}
|
||||
21
PointOfSale/Pos.Api/Pos.Api.Database/Models/SaleLine.cs
Normal file
21
PointOfSale/Pos.Api/Pos.Api.Database/Models/SaleLine.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pos.Api.Database.Models;
|
||||
|
||||
public partial class SaleLine
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int SaleId { get; set; }
|
||||
|
||||
public string Product { get; set; }
|
||||
|
||||
public short Pieces { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public decimal Total { get; set; }
|
||||
}
|
||||
15
PointOfSale/Pos.Api/Pos.Api.Database/Pos.Api.Database.csproj
Normal file
15
PointOfSale/Pos.Api/Pos.Api.Database/Pos.Api.Database.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" 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>
|
||||
66
PointOfSale/Pos.Api/Pos.Api.Database/efpt.config.json
Normal file
66
PointOfSale/Pos.Api/Pos.Api.Database/efpt.config.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"CodeGenerationMode": 3,
|
||||
"ContextClassName": "PosApiContext",
|
||||
"ContextNamespace": null,
|
||||
"DefaultDacpacSchema": null,
|
||||
"FilterSchemas": false,
|
||||
"IncludeConnectionString": false,
|
||||
"ModelNamespace": null,
|
||||
"OutputContextPath": "Data",
|
||||
"OutputPath": "Models",
|
||||
"PreserveCasingWithRegex": true,
|
||||
"ProjectRootNamespace": "Pos.Api.Database",
|
||||
"Schemas": null,
|
||||
"SelectedHandlebarsLanguage": 0,
|
||||
"SelectedToBeGenerated": 0,
|
||||
"Tables": [
|
||||
{
|
||||
"Name": "employee",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "LastUpdate",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "payment",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "product",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "productgroup",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "sale",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "sale_line",
|
||||
"ObjectType": 0
|
||||
}
|
||||
],
|
||||
"UiHint": "simply.com",
|
||||
"UncountableWords": null,
|
||||
"UseBoolPropertiesWithoutDefaultSql": false,
|
||||
"UseDatabaseNames": false,
|
||||
"UseDateOnlyTimeOnly": false,
|
||||
"UseDbContextSplitting": false,
|
||||
"UseFluentApiOnly": true,
|
||||
"UseHandleBars": false,
|
||||
"UseHierarchyId": false,
|
||||
"UseInflector": true,
|
||||
"UseLegacyPluralizer": false,
|
||||
"UseManyToManyEntity": false,
|
||||
"UseNoDefaultConstructor": false,
|
||||
"UseNoObjectFilter": false,
|
||||
"UseNodaTime": false,
|
||||
"UseNullableReferences": false,
|
||||
"UseSchemaFolders": false,
|
||||
"UseSchemaNamespaces": false,
|
||||
"UseSpatial": false,
|
||||
"UseT4": false
|
||||
}
|
||||
29
PointOfSale/Pos.Api/Pos.Api/BaseController.cs
Normal file
29
PointOfSale/Pos.Api/Pos.Api/BaseController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Pos.Api.Database;
|
||||
|
||||
namespace Pos.Api
|
||||
{
|
||||
public class BaseController : Controller
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
public BaseController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context,
|
||||
ActionExecutionDelegate next)
|
||||
{
|
||||
HttpRequest request = Request;
|
||||
string apiKey = request.Headers["ApiKey"].ToString();
|
||||
string? apiKeyRequest = _config["ApiKey"];
|
||||
if (apiKeyRequest == null)
|
||||
{
|
||||
throw new NullReferenceException("ApiKey header is missing");
|
||||
}
|
||||
|
||||
if (!apiKeyRequest.Equals(apiKey))
|
||||
throw new ArgumentException("ApiKey is wrong");
|
||||
}
|
||||
}
|
||||
}
|
||||
151
PointOfSale/Pos.Api/Pos.Api/Controllers/PosController.cs
Normal file
151
PointOfSale/Pos.Api/Pos.Api/Controllers/PosController.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Pos.Api.Database.Data;
|
||||
using Pos.Api.Database.Models;
|
||||
|
||||
namespace Pos.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PosController : Controller
|
||||
{
|
||||
private readonly PosApiContext _context;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public PosController(IConfiguration config, PosApiContext context)
|
||||
{
|
||||
_context = context;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
//[HttpGet("/update")]
|
||||
//public DateTime LastUpdate()
|
||||
//{
|
||||
|
||||
// LastUpdate? lastUpdate = _context.LastUpdates.SingleOrDefault();
|
||||
// if (lastUpdate == null)
|
||||
// {
|
||||
// return DateTime.Now;
|
||||
// }
|
||||
|
||||
// DateTime last = lastUpdate.DateTime.Value;
|
||||
// lastUpdate.DateTime = DateTime.Now;
|
||||
// _context.SaveChanges();
|
||||
|
||||
// return last;
|
||||
//}
|
||||
|
||||
[HttpPost("/employee")]
|
||||
public void Employee(Employee employee)
|
||||
{
|
||||
ValidateApiKey();
|
||||
|
||||
Employee? dbEmployee = _context.Employees.SingleOrDefault(c => c.Id == employee.Id);
|
||||
if (dbEmployee == null)
|
||||
{
|
||||
dbEmployee = new Employee();
|
||||
dbEmployee.Id = employee.Id;
|
||||
dbEmployee.IsArchived = employee.IsArchived;
|
||||
_context.Employees.Add(dbEmployee);
|
||||
}
|
||||
dbEmployee.Name = employee.Name;
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
[HttpPost("/productgroup")]
|
||||
public void Product(Productgroup productGroup)
|
||||
{
|
||||
ValidateApiKey();
|
||||
|
||||
Productgroup dbProductGroup = _context.Productgroups.SingleOrDefault(c => c.Id == productGroup.Id);
|
||||
if (dbProductGroup == null)
|
||||
{
|
||||
dbProductGroup = new Productgroup();
|
||||
dbProductGroup.Id = productGroup.Id;
|
||||
_context.Productgroups.Add(dbProductGroup);
|
||||
}
|
||||
dbProductGroup.IsArchived = productGroup.IsArchived;
|
||||
dbProductGroup.Name = productGroup.Name;
|
||||
dbProductGroup.Index = productGroup.Index;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
[HttpPost("/sale")]
|
||||
public void Sale(Sale sale)
|
||||
{
|
||||
ValidateApiKey();
|
||||
|
||||
Sale? dbSale = _context.Sales.SingleOrDefault(c => c.Id == sale.Id);
|
||||
if (dbSale == null)
|
||||
{
|
||||
dbSale = new Sale();
|
||||
dbSale.Id = sale.Id;
|
||||
_context.Sales.Add(dbSale);
|
||||
}
|
||||
dbSale.EmployeeId = sale.EmployeeId;
|
||||
dbSale.Time = sale.Time;
|
||||
_context.SaveChanges();
|
||||
|
||||
}
|
||||
|
||||
[HttpPost("/saleline")]
|
||||
public void SaleLine(SaleLine saleLine)
|
||||
{
|
||||
ValidateApiKey();
|
||||
|
||||
SaleLine? dbSaleLine = _context.SaleLines.SingleOrDefault(c => c.Id == saleLine.Id);
|
||||
if (dbSaleLine == null)
|
||||
{
|
||||
dbSaleLine = new SaleLine();
|
||||
dbSaleLine.Id = saleLine.Id;
|
||||
_context.SaleLines.Add(dbSaleLine);
|
||||
}
|
||||
dbSaleLine.SaleId = saleLine.SaleId;
|
||||
dbSaleLine.Price = saleLine.Price;
|
||||
dbSaleLine.Pieces = saleLine.Pieces;
|
||||
dbSaleLine.Price = saleLine.Price;
|
||||
dbSaleLine.Product = saleLine.Product;
|
||||
dbSaleLine.Total = saleLine.Total;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
[HttpPost("/payment")]
|
||||
public void Payment(Payment payment)
|
||||
{
|
||||
ValidateApiKey();
|
||||
|
||||
Payment? dbPayment = _context.Payments.SingleOrDefault(c => c.Id == payment.Id);
|
||||
if (dbPayment == null)
|
||||
{
|
||||
dbPayment = new Payment();
|
||||
dbPayment.Id = payment.Id;
|
||||
_context.Payments.Add(dbPayment);
|
||||
}
|
||||
dbPayment.Amount = payment.Amount;
|
||||
dbPayment.SaleId = payment.SaleId;
|
||||
dbPayment.Type = payment.Type;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
private void ValidateApiKey()
|
||||
{
|
||||
IHeaderDictionary headers = Request.Headers;
|
||||
if (!headers.ContainsKey("ApiKey"))
|
||||
{
|
||||
throw new MissingFieldException("ApiKey missing");
|
||||
}
|
||||
|
||||
StringValues apiKeyHeader = headers["ApiKey"];
|
||||
string? apiKey = _config["ApiKey"];
|
||||
if (!apiKeyHeader.Equals(apiKey))
|
||||
{
|
||||
throw new MissingFieldException("ApiKey is wrong");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Pos.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Pos.Api.Database;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace Pos.Api.Helper
|
||||
{
|
||||
public class ApiKeyHeaderOperationFilter : IOperationFilter
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public ApiKeyHeaderOperationFilter(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
string? apiKey = _config["ApiKey"];
|
||||
operation.Parameters.Add(new OpenApiParameter
|
||||
{
|
||||
Name = "ApiKey",
|
||||
In = ParameterLocation.Header,
|
||||
Required = true,
|
||||
Schema = new OpenApiSchema
|
||||
{
|
||||
Type = "string",
|
||||
Default = new OpenApiString(apiKey)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
55
PointOfSale/Pos.Api/Pos.Api/Helper/LoadConfig.cs
Normal file
55
PointOfSale/Pos.Api/Pos.Api/Helper/LoadConfig.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Pos.Api.Helper
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
PointOfSale/Pos.Api/Pos.Api/Pos.Api.csproj
Normal file
24
PointOfSale/Pos.Api/Pos.Api/Pos.Api.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pos.Api.Database\Pos.Api.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
32
PointOfSale/Pos.Api/Pos.Api/Program.cs
Normal file
32
PointOfSale/Pos.Api/Pos.Api/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Pos.Api.Database;
|
||||
using Pos.Api.Database.Data;
|
||||
using Pos.Api.Helper;
|
||||
using LoadConfig = Pos.Api.Helper.LoadConfig;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
LoadConfig loadConfig = new LoadConfig();
|
||||
IConfiguration config = loadConfig.ByEnvironment();
|
||||
builder.Services.AddSingleton(config);
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
c.OperationFilter<ApiKeyHeaderOperationFilter>()
|
||||
);
|
||||
builder.Services.AddDbContext<PosApiContext>();
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
31
PointOfSale/Pos.Api/Pos.Api/Properties/launchSettings.json
Normal file
31
PointOfSale/Pos.Api/Pos.Api/Properties/launchSettings.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:53151",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5297",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
PointOfSale/Pos.Api/Pos.Api/WeatherForecast.cs
Normal file
13
PointOfSale/Pos.Api/Pos.Api/WeatherForecast.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Pos.Api
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
8
PointOfSale/Pos.Api/Pos.Api/appsettings.Development.json
Normal file
8
PointOfSale/Pos.Api/Pos.Api/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
PointOfSale/Pos.Api/Pos.Api/appsettings.json
Normal file
11
PointOfSale/Pos.Api/Pos.Api/appsettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"MySQL": "Data Source=mysql22.unoeuro.com;Initial Catalog=blomstertilalt_dk_db;Persist Security Info=False;User ID=blomstertil_dk;Password=amccpy6l",
|
||||
"ApiKey": "ad0YfMYm5bdVGjmXkJBOdNggQaWtkB9nzyQv68GAcB7mpf9onGBP9j3DJ46S7go30NwaQgoZBNS7hZDOM79KTyU3K2ysMW2x4mWGHOkETJmWadaMXBTGpoWn0ef9KiUN"
|
||||
}
|
||||
Reference in New Issue
Block a user