diff --git a/Cloud_Manager.sln b/Cloud_Manager.sln new file mode 100644 index 0000000..38b8308 --- /dev/null +++ b/Cloud_Manager.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33530.505 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cloud_Manager", "Cloud_Manager\Cloud_Manager.csproj", "{D2BD9F08-9AD5-4ECB-B60F-C507F6DB0B22}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2BD9F08-9AD5-4ECB-B60F-C507F6DB0B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D2BD9F08-9AD5-4ECB-B60F-C507F6DB0B22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D2BD9F08-9AD5-4ECB-B60F-C507F6DB0B22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D2BD9F08-9AD5-4ECB-B60F-C507F6DB0B22}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B00F402F-EC33-41CE-9AEE-FB56B36DEEE3} + EndGlobalSection +EndGlobal diff --git a/Cloud_Manager/BiskAcdbContext.cs b/Cloud_Manager/BiskAcdbContext.cs new file mode 100644 index 0000000..dc812cf --- /dev/null +++ b/Cloud_Manager/BiskAcdbContext.cs @@ -0,0 +1,1388 @@ +using Biskilog_Accounting.Server.POSModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; + +namespace Cloud_Manager; + +public partial class BiskAcdbContext : DbContext +{ + private readonly HttpContext m_httpContext; + private readonly IConnectionService m_connection; + private readonly ITokenService m_tokenService; + public BiskAcdbContext() + { + } + public BiskAcdbContext(DbContextOptions options, ITokenService tokenService, IConnectionService connection, IHttpContextAccessor a_httpContextAccessor = null) + : base(options) + { + m_tokenService = tokenService; + m_connection = connection; + m_httpContext = a_httpContextAccessor?.HttpContext; + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + int? databaseId = m_tokenService.GetDatabaseIdFromToken(token); + string connectionString = m_connection.GetClientConnectionString(databaseId!.Value); + optionsBuilder.UseMySql(connectionString, new MariaDbServerVersion(new Version())); + } + else + { + m_httpContext.Abort(); + } + } + } + public virtual DbSet Creditpurchases { get; set; } + + public virtual DbSet Customeraccounts { get; set; } + + public virtual DbSet Productaltunits { get; set; } + + public virtual DbSet Restocklevels { get; set; } + + public virtual DbSet Systemuserroles { get; set; } + + public virtual DbSet Tblbranches { get; set; } + + public virtual DbSet Tblbrands { get; set; } + + public virtual DbSet Tblcancelledtransactions { get; set; } + + public virtual DbSet Tblcarts { get; set; } + + public virtual DbSet Tblcategories { get; set; } + + public virtual DbSet Tblcompanydetails { get; set; } + + public virtual DbSet Tblcustomers { get; set; } + + public virtual DbSet Tblcustomerpurchases { get; set; } + + public virtual DbSet Tbldeliverydetails { get; set; } + + public virtual DbSet Tbldeliveryheads { get; set; } + + public virtual DbSet Tbldeliveryrecipients { get; set; } + + public virtual DbSet Tbldiscountlogs { get; set; } + + public virtual DbSet Tbldrivers { get; set; } + + public virtual DbSet Tblinventories { get; set; } + + public virtual DbSet Tblinventoryentries { get; set; } + + public virtual DbSet Tblinvoices { get; set; } + + public virtual DbSet Tblpricechanges { get; set; } + + public virtual DbSet Tblproducts { get; set; } + public virtual DbSet Tblsyncinfos { get; set; } + public virtual DbSet Tbltrucks { get; set; } + + public virtual DbSet TbltruckDrivermappings { get; set; } + + public virtual DbSet Tbltruckassignments { get; set; } + + public virtual DbSet Tbltruckinventories { get; set; } + + public virtual DbSet Tblusers { get; set; } + + public virtual DbSet Tbstocks { get; set; } + + public virtual DbSet Unitofmeasures { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.ReceiptId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("creditpurchases") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.ReceiptId) + .HasMaxLength(120) + .HasColumnName("receiptID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("'0'") + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.CustomerId) + .HasMaxLength(120) + .HasDefaultValueSql("'0'") + .HasColumnName("customerID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Date) + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("current_timestamp()") + .HasColumnType("timestamp") + .HasColumnName("date"); + entity.Property(e => e.Paid) + .HasPrecision(19, 2) + .HasColumnName("paid"); + entity.Property(e => e.Status) + .HasMaxLength(10) + .HasDefaultValueSql("'0'") + .IsFixedLength() + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.TotalBill) + .HasPrecision(19, 2) + .HasColumnName("totalBill"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("customeraccounts") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.CountId) + .HasMaxLength(120) + .HasDefaultValueSql("''") + .HasColumnName("countID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Balance) + .HasPrecision(19, 2) + .HasColumnName("balance"); + entity.Property(e => e.Comments) + .HasColumnType("text") + .HasColumnName("comments") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Credit) + .HasPrecision(19, 2) + .HasColumnName("credit"); + entity.Property(e => e.CustomerId) + .HasMaxLength(120) + .HasColumnName("customerID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Date) + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("current_timestamp()") + .HasColumnType("timestamp") + .HasColumnName("date"); + entity.Property(e => e.Debit) + .HasPrecision(19, 2) + .HasColumnName("debit"); + entity.Property(e => e.TransactionId) + .HasMaxLength(120) + .HasColumnName("transactionID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.DistinctiveCode, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("productaltunit") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.DistinctiveCode) + .HasMaxLength(120) + .HasColumnName("distinctiveCode") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchId) + .HasMaxLength(120) + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Pcode) + .HasMaxLength(120) + .HasColumnName("pcode") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.PriceUnit) + .HasPrecision(19, 2) + .HasColumnName("price/unit"); + entity.Property(e => e.QuantityUnit) + .HasColumnType("int(11)") + .HasColumnName("quantity/unit"); + entity.Property(e => e.UnitBarcode) + .HasMaxLength(20) + .HasColumnName("unitBarcode") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.UnitCode) + .HasMaxLength(120) + .HasColumnName("unitCode") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.ProductId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("restocklevels") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.ProductId) + .HasMaxLength(150) + .HasColumnName("productID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchId) + .HasMaxLength(20) + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Unit) + .HasMaxLength(150) + .HasColumnName("unit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.WarnLevel) + .HasColumnType("int(11)") + .HasColumnName("warnLevel"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PRIMARY"); + + entity + .ToTable("systemuserroles") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnType("int(11)") + .HasColumnName("id"); + entity.Property(e => e.Assist) + .HasColumnType("tinyint(4)") + .HasColumnName("assist"); + entity.Property(e => e.Cashier) + .HasColumnType("tinyint(4)") + .HasColumnName("cashier"); + entity.Property(e => e.Manager) + .HasColumnType("tinyint(4)") + .HasColumnName("manager"); + entity.Property(e => e.Owner) + .HasColumnType("tinyint(4)") + .HasColumnName("owner"); + entity.Property(e => e.Roles) + .HasColumnName("roles") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.BranchId).HasName("PRIMARY"); + + entity + .ToTable("tblbranches") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(12) + .HasColumnName("branchID"); + entity.Property(e => e.Address) + .HasMaxLength(50) + .HasColumnName("address") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchName) + .HasMaxLength(50) + .HasColumnName("branchName") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchTelephone) + .HasMaxLength(50) + .HasColumnName("branch_telephone") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.City) + .HasMaxLength(50) + .HasColumnName("city") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.StateOrProvince) + .HasMaxLength(50) + .HasColumnName("state_or_province") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Id, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblbrand") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Id) + .HasMaxLength(50) + .HasColumnName("id"); + entity.Property(e => e.BranchId) + .HasMaxLength(12) + .HasColumnName("branchID"); + entity.Property(e => e.Brand) + .HasMaxLength(50) + .HasColumnName("brand") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblcancelledtransactions") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(50) + .HasColumnName("branchID"); + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.CancelledBy) + .HasMaxLength(50) + .HasColumnName("cancelledBy") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.DateCancelled) + .HasColumnType("timestamp") + .HasColumnName("dateCancelled"); + entity.Property(e => e.Transno) + .HasColumnName("transno") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblcart") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.CountId) + .HasMaxLength(200) + .HasColumnName("countID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Cashier) + .HasMaxLength(50) + .HasColumnName("cashier"); + entity.Property(e => e.Costprice) + .HasPrecision(19, 2) + .HasColumnName("costprice"); + entity.Property(e => e.Date) + .HasColumnType("timestamp") + .HasColumnName("date"); + entity.Property(e => e.Id) + .HasMaxLength(50) + .HasColumnName("id"); + entity.Property(e => e.Price) + .HasPrecision(19, 2) + .HasColumnName("price"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + entity.Property(e => e.Status) + .HasMaxLength(50) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Total) + .HasPrecision(19, 2) + .HasColumnName("total"); + entity.Property(e => e.Transno) + .HasColumnName("transno") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Unit) + .HasMaxLength(120) + .HasColumnName("unit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Tendered) + .HasPrecision(19, 2) + .HasColumnName("tendered"); + entity.Property(e => e.Balance) + .HasPrecision(19, 2) + .HasColumnName("balance"); + entity.Property(e => e.ValueAddTax) + .HasPrecision(19, 2) + .HasColumnName("valueAddTax"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Id, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblcategory") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Id) + .HasMaxLength(50) + .HasColumnName("id"); + entity.Property(e => e.BranchId) + .HasMaxLength(12) + .HasColumnName("branchID"); + entity.Property(e => e.Category) + .HasMaxLength(50) + .HasColumnName("category") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Tin).HasName("PRIMARY"); + + entity + .ToTable("tblcompanydetails") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Tin) + .HasMaxLength(60) + .HasColumnName("tin"); + entity.Property(e => e.Address) + .HasMaxLength(50) + .HasColumnName("address") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.CompanyName) + .HasMaxLength(50) + .HasColumnName("company_name") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Email) + .HasMaxLength(50) + .HasColumnName("email") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.MainTelephone) + .HasMaxLength(50) + .HasColumnName("main_telephone"); + entity.Property(e => e.Vatno) + .HasMaxLength(60) + .HasColumnName("vatno"); + entity.Property(e => e.Website) + .HasMaxLength(50) + .HasColumnName("website") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CustomerId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblcustomers") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CustomerId) + .HasMaxLength(30) + .HasColumnName("customerID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Address) + .HasMaxLength(50) + .HasColumnName("address") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.DateAdded) + .HasColumnType("timestamp") + .HasColumnName("dateAdded"); + entity.Property(e => e.DateExit) + .HasColumnType("timestamp") + .HasColumnName("dateExit"); + entity.Property(e => e.Email) + .HasMaxLength(50) + .HasColumnName("email"); + entity.Property(e => e.FinancialStatus) + .HasMaxLength(20) + .HasColumnName("financialStatus") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Firstname) + .HasMaxLength(50) + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.NameKey1) + .HasMaxLength(120) + .HasColumnName("name_key1") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.NameKey2) + .HasMaxLength(120) + .HasColumnName("name_key2") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Status) + .HasMaxLength(20) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Surname) + .HasMaxLength(50) + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Telephone) + .HasMaxLength(50) + .HasColumnName("telephone") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Tin) + .HasMaxLength(50) + .HasColumnName("tin"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblcustomerpurchases") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.CustomerId) + .HasMaxLength(50) + .HasColumnName("customerID"); + entity.Property(e => e.TransactionId) + .HasMaxLength(50) + .HasColumnName("transactionID"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbldeliverydetails") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(100) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Cost) + .HasPrecision(19, 2) + .HasColumnName("cost"); + entity.Property(e => e.DeliveryId) + .HasMaxLength(60) + .HasColumnName("deliveryID"); + entity.Property(e => e.Pcode) + .HasMaxLength(60) + .HasColumnName("pcode"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + entity.Property(e => e.Unit) + .HasMaxLength(120) + .HasColumnName("unit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.DeliveryId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbldeliveryhead") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.DeliveryId) + .HasMaxLength(60) + .HasColumnName("deliveryID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.CustomerId) + .HasMaxLength(60) + .HasColumnName("customerID"); + entity.Property(e => e.DateCompleted) + .HasMaxLength(6) + .HasColumnName("dateCompleted"); + entity.Property(e => e.DateInitiated) + .HasMaxLength(6) + .HasColumnName("dateInitiated"); + entity.Property(e => e.Destination) + .HasMaxLength(60) + .HasColumnName("destination"); + entity.Property(e => e.GeneratedBy) + .HasMaxLength(50) + .HasColumnName("generatedBy") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Status) + .HasMaxLength(20) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.TotalCost) + .HasPrecision(19, 2) + .HasColumnName("totalCost"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.DeliveryId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbldeliveryrecipients") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.DeliveryId) + .HasMaxLength(60) + .HasColumnName("deliveryID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Address) + .HasMaxLength(60) + .HasColumnName("address"); + entity.Property(e => e.CustomerId) + .HasMaxLength(60) + .HasColumnName("customerID"); + entity.Property(e => e.Email) + .HasMaxLength(60) + .HasColumnName("email"); + entity.Property(e => e.FromDate).HasColumnName("fromDate"); + entity.Property(e => e.Fullname) + .HasColumnName("fullname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Telephone) + .HasMaxLength(15) + .HasColumnName("telephone") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.ToDate).HasColumnName("toDate"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbldiscountlogs") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.CountId) + .HasMaxLength(150) + .HasDefaultValueSql("''") + .HasColumnName("countID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Cashier) + .HasMaxLength(50) + .HasColumnName("cashier") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Date) + .HasMaxLength(6) + .HasColumnName("date"); + entity.Property(e => e.Discount) + .HasPrecision(19, 2) + .HasColumnName("discount"); + entity.Property(e => e.ReceiptId) + .HasMaxLength(50) + .HasColumnName("receiptID"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.DriverId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbldrivers") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.DriverId) + .HasMaxLength(50) + .HasColumnName("driverID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Address1) + .HasMaxLength(50) + .HasColumnName("address1") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Address2) + .HasMaxLength(50) + .HasColumnName("address2") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.City) + .HasMaxLength(50) + .HasColumnName("city") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.DateOfBirth).HasColumnName("dateOfBirth"); + entity.Property(e => e.Email) + .HasMaxLength(120) + .HasColumnName("email") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Firstname) + .HasMaxLength(50) + .HasColumnName("firstname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Middlename) + .HasMaxLength(50) + .HasColumnName("middlename") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.State) + .HasMaxLength(50) + .HasColumnName("state") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Status) + .HasMaxLength(50) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Surname) + .HasMaxLength(50) + .HasColumnName("surname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Telephone) + .HasMaxLength(20) + .HasColumnName("telephone") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BranchId, e.CountId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblinventory") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblinventoryentries") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(120) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Date) + .HasMaxLength(6) + .HasColumnName("date"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblinvoice") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.DateGenerated).HasColumnName("dateGenerated"); + entity.Property(e => e.GeneratedBy) + .HasMaxLength(50) + .HasColumnName("generatedBy"); + entity.Property(e => e.InvoiceId) + .HasMaxLength(60) + .HasColumnName("invoiceID"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + entity.Property(e => e.Status) + .HasMaxLength(16) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Totalprice) + .HasPrecision(19, 2) + .HasColumnName("totalprice"); + entity.Property(e => e.Unit) + .HasMaxLength(120) + .HasColumnName("unit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Unitprice) + .HasPrecision(19, 2) + .HasColumnName("unitprice"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblpricechanges") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(70) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.ChangeDate) + .HasMaxLength(6) + .HasColumnName("change_date"); + entity.Property(e => e.CurrentPrice) + .HasPrecision(19, 2) + .HasColumnName("current_price"); + entity.Property(e => e.Pcode) + .HasMaxLength(120) + .HasColumnName("pcode"); + entity.Property(e => e.PreviousPrice) + .HasPrecision(19, 2) + .HasColumnName("previous_price"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblproduct") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Barcode) + .HasMaxLength(50) + .HasColumnName("barcode") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BaseUnit) + .HasMaxLength(120) + .HasColumnName("baseUnit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Bid) + .HasMaxLength(50) + .HasColumnName("bid"); + entity.Property(e => e.Cid) + .HasMaxLength(50) + .HasColumnName("cid"); + entity.Property(e => e.Costprice) + .HasPrecision(19, 2) + .HasColumnName("costprice"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Pdesc) + .HasColumnName("pdesc") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Price) + .HasPrecision(19, 2) + .HasColumnName("price"); + entity.Property(e => e.ProductName) + .HasColumnName("product_name") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Status) + .HasMaxLength(20) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.TableName).HasName("PRIMARY"); + + entity.ToTable("tblsyncinfo"); + + entity.Property(e => e.TableName) + .HasMaxLength(150) + .HasColumnName("tableName"); + entity.Property(e => e.BranchId) + .HasMaxLength(50) + .IsFixedLength() + .HasColumnName("branchId"); + entity.Property(e => e.LastSyncDate).HasColumnType("timestamp"); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.TruckId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbltrucks") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.TruckId) + .HasMaxLength(60) + .HasColumnName("truckID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Brand) + .HasMaxLength(50) + .HasColumnName("brand") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Driver) + .HasMaxLength(50) + .HasColumnName("driver"); + entity.Property(e => e.LicensePlate) + .HasMaxLength(60) + .HasColumnName("licensePlate"); + entity.Property(e => e.Weight) + .HasPrecision(19, 2) + .HasColumnName("weight"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbltruck_drivermapping") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(60) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.DateEntry) + .HasMaxLength(6) + .HasColumnName("dateEntry"); + entity.Property(e => e.DriverId) + .HasMaxLength(50) + .HasColumnName("driverID"); + entity.Property(e => e.Operation) + .HasMaxLength(50) + .HasColumnName("operation") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.TruckId) + .HasMaxLength(50) + .HasColumnName("truckID"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbltruckassignments") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(100) + .HasColumnName("countID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Cost) + .HasPrecision(19, 2) + .HasColumnName("cost"); + entity.Property(e => e.DateAssigned) + .HasMaxLength(6) + .HasColumnName("dateAssigned"); + entity.Property(e => e.OrderId) + .HasMaxLength(50) + .HasColumnName("orderID"); + entity.Property(e => e.Status) + .HasMaxLength(50) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.TruckId) + .HasMaxLength(50) + .HasColumnName("truckID"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbltruckinventory") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Quantity) + .HasColumnType("int(11)") + .HasColumnName("quantity"); + entity.Property(e => e.TruckId) + .HasMaxLength(50) + .HasColumnName("truckID"); + entity.Property(e => e.Unit) + .HasMaxLength(120) + .HasColumnName("unit") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Username, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tblusers") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Username) + .HasMaxLength(50) + .HasColumnName("username"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.AccessLevel) + .HasMaxLength(10) + .HasColumnName("access_level") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.City) + .HasMaxLength(50) + .HasColumnName("city") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Email) + .HasMaxLength(50) + .HasColumnName("email") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Firstname) + .HasMaxLength(50) + .HasColumnName("firstname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.LastLogin) + .HasMaxLength(6) + .HasColumnName("last_login"); + entity.Property(e => e.Password) + .HasColumnName("password") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.StateOrProvince) + .HasMaxLength(50) + .HasColumnName("state_or_province") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.StreetAddress1) + .HasMaxLength(50) + .HasColumnName("street_address1") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.StreetAddress2) + .HasMaxLength(50) + .HasColumnName("street_address2") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Surname) + .HasMaxLength(50) + .HasColumnName("surname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Telephone) + .HasMaxLength(15) + .HasColumnName("telephone") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CountId, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("tbstock") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.CountId) + .HasMaxLength(50) + .HasColumnName("countID"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .IsFixedLength() + .HasColumnName("branchID"); + entity.Property(e => e.Pcode) + .HasMaxLength(50) + .HasColumnName("pcode"); + entity.Property(e => e.Qty) + .HasColumnType("int(11)") + .HasColumnName("qty"); + entity.Property(e => e.Refno) + .HasMaxLength(50) + .HasColumnName("refno"); + entity.Property(e => e.Sdate).HasColumnName("sdate"); + entity.Property(e => e.Stockinby) + .HasMaxLength(50) + .HasColumnName("stockinby") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.UnitCode, e.BranchId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("unitofmeasure") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.UnitCode) + .HasMaxLength(120) + .HasColumnName("unitCode"); + entity.Property(e => e.BranchId) + .HasMaxLength(10) + .HasDefaultValueSql("''") + .IsFixedLength() + .HasColumnName("branchID") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Status) + .HasMaxLength(50) + .HasColumnName("status") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Unitname) + .HasMaxLength(120) + .HasColumnName("unitname") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Unitshort) + .HasMaxLength(120) + .HasColumnName("unitshort") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/Cloud_Manager/BiskilogContext.cs b/Cloud_Manager/BiskilogContext.cs new file mode 100644 index 0000000..28d7a91 --- /dev/null +++ b/Cloud_Manager/BiskilogContext.cs @@ -0,0 +1,280 @@ +using System; +using System.Collections.Generic; +using Cloud_Manager.Models.ClientContractModels; +using Microsoft.EntityFrameworkCore; + +namespace Cloud_Manager; +/// +/// This is the main EF DbContext for the Biskilog Accounting +/// +public partial class BiskilogContext : DbContext +{ + public BiskilogContext() + { + } + public BiskilogContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Authtypes { get; set; } + + public virtual DbSet Clientbusinesses { get; set; } + + public virtual DbSet Clientinfos { get; set; } + + public virtual DbSet Contracts { get; set; } + + public virtual DbSet Databasemaps { get; set; } + + public virtual DbSet Siteaccesspermissions { get; set; } + + public virtual DbSet Userauths { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PRIMARY"); + + entity + .ToTable("authtypes") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.Id) + .HasColumnType("int(11)") + .HasColumnName("id"); + entity.Property(e => e.Type) + .HasMaxLength(50) + .HasColumnName("type") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.BusinessId, e.ClientId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 }); + + entity + .ToTable("clientbusiness") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.BusinessId) + .HasComment("there could be multiple branches of the same business") + .HasColumnType("int(11)") + .HasColumnName("businessId"); + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientID"); + entity.Property(e => e.BiskilogVersion) + .HasMaxLength(50) + .HasDefaultValueSql("''") + .HasColumnName("biskilog_version") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.BusinessName) + .HasMaxLength(50) + .HasDefaultValueSql("''") + .HasColumnName("business_name") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.DateJoined) + .HasDefaultValueSql("current_timestamp()") + .HasColumnType("datetime") + .HasColumnName("date_joined"); + entity.Property(e => e.BusinessExternalId) + .HasMaxLength(50) + .HasDefaultValueSql("''") + .HasColumnName("businessExternalId") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ClientId).HasName("PRIMARY"); + + entity + .ToTable("clientinfo") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientID"); + entity.Property(e => e.Email) + .HasMaxLength(200) + .HasColumnName("email") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Fullname) + .HasMaxLength(200) + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.PhoneNumber) + .HasMaxLength(200) + .HasColumnName("phoneNumber") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ContractId).HasName("PRIMARY"); + + entity + .ToTable("contracts") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.HasIndex(e => new { e.ClientId, e.BusinessId }, "clientId_businessId").IsUnique(); + + entity.Property(e => e.ContractId) + .HasColumnType("int(11)") + .HasColumnName("contractId"); + entity.Property(e => e.Bill) + .HasPrecision(18, 2) + .HasColumnName("bill"); + entity.Property(e => e.BusinessId) + .HasColumnType("int(11)") + .HasColumnName("businessId"); + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientId"); + entity.Property(e => e.Comments) + .HasColumnType("text") + .HasColumnName("comments") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.EndDate) + .HasColumnType("datetime") + .HasColumnName("end_date"); + entity.Property(e => e.StartDate) + .HasColumnType("datetime") + .HasColumnName("start_date"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DbNo).HasName("PRIMARY"); + + entity + .ToTable("databasemap") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.HasIndex(e => e.ClientId, "businessId").IsUnique(); + + entity.Property(e => e.DbNo) + .HasColumnType("int(11)") + .HasColumnName("db_no"); + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientID"); + entity.Property(e => e.DbName) + .HasMaxLength(50) + .HasDefaultValueSql("''") + .HasColumnName("db_name") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Domain) + .HasMaxLength(50) + .HasDefaultValueSql("''") + .HasColumnName("domain") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.LastSyncDate) + .HasColumnType("datetime") + .HasColumnName("last_sync_date"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.UserId, e.BusinessId, e.ClientId }) + .HasName("PRIMARY") + .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0, 0 }); + + entity + .ToTable("siteaccesspermission") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.Property(e => e.UserId) + .HasColumnType("int(11)") + .HasColumnName("userID"); + entity.Property(e => e.BusinessId) + .HasComment("businessIds could also been seen as branchID") + .HasColumnType("int(11)") + .HasColumnName("businessId"); + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientId"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.UserId).HasName("PRIMARY"); + + entity + .ToTable("userauth") + .HasCharSet("utf8") + .UseCollation("utf8_general_ci"); + + entity.HasIndex(e => e.AuthType, "authType"); + + entity.HasIndex(e => new { e.ClientId, e.Username, e.Email }, "clientId_username_email").IsUnique(); + + entity.Property(e => e.UserId) + .HasColumnType("int(11)") + .HasColumnName("userId"); + entity.Property(e => e.AuthType) + .HasColumnType("int(11)") + .HasColumnName("authType"); + entity.Property(e => e.ClientId) + .HasColumnType("int(11)") + .HasColumnName("clientId"); + entity.Property(e => e.Email) + .HasMaxLength(200) + .HasColumnName("email") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Isactive) + .HasColumnType("bit(1)") + .HasColumnName("isactive"); + entity.Property(e => e.Isowner) + .HasColumnType("bit(1)") + .HasColumnName("isowner"); + entity.Property(e => e.LastLogin) + .HasColumnType("datetime") + .HasColumnName("last_login"); + entity.Property(e => e.Passsword) + .HasMaxLength(200) + .HasColumnName("passsword") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.PhoneNumber) + .HasMaxLength(50) + .HasColumnName("phoneNumber") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + entity.Property(e => e.Username) + .HasMaxLength(30) + .HasColumnName("username") + .UseCollation("utf8mb4_general_ci") + .HasCharSet("utf8mb4"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/Cloud_Manager/CloudHubs/SalesHub.cs b/Cloud_Manager/CloudHubs/SalesHub.cs new file mode 100644 index 0000000..344e1a4 --- /dev/null +++ b/Cloud_Manager/CloudHubs/SalesHub.cs @@ -0,0 +1,18 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Interfaces; +using Microsoft.AspNetCore.SignalR; + +namespace Cloud_Manager.CloudHubs +{ + public class SalesHub : Hub + { + public async Task JoinCompanyGroup(string a_companyId) + { + await Groups.AddToGroupAsync(Context.ConnectionId, a_companyId); + } + public async Task AddTransaction(string a_companyId, SaleItem a_sale) + { + await Clients.OthersInGroup(a_companyId).TransactionMade(a_sale); + } + } +} diff --git a/Cloud_Manager/Cloud_Manager.csproj b/Cloud_Manager/Cloud_Manager.csproj new file mode 100644 index 0000000..c897fec --- /dev/null +++ b/Cloud_Manager/Cloud_Manager.csproj @@ -0,0 +1,16 @@ + + + + net7.0 + enable + enable + + + + + + + + + + diff --git a/Cloud_Manager/Controllers/SyncControllers/SyncCompanyInfoController.cs b/Cloud_Manager/Controllers/SyncControllers/SyncCompanyInfoController.cs new file mode 100644 index 0000000..945a05b --- /dev/null +++ b/Cloud_Manager/Controllers/SyncControllers/SyncCompanyInfoController.cs @@ -0,0 +1,151 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Runtime.InteropServices; + +namespace Cloud_Manager.Controllers.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncCompanyInfoController : ControllerBase + { + private readonly ISalesInterface m_salesService; + private readonly ICustomer m_customer; + private readonly IUser m_users; + private readonly ICompanyInfo m_companyInfo; + public SyncCompanyInfoController(ISalesInterface a_salesService, ICustomer customer, IUser users, ICompanyInfo a_companyInfo) + { + m_salesService = a_salesService; + m_customer = customer; + m_users = users; + m_companyInfo = a_companyInfo; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_salesService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of SystemUserRoles rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/SystemRoles")] + public async Task SyncSyatemRolesAsync(List a_item) + { + await m_companyInfo.SyncSystemRoles(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblDriver rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDriver")] + public async Task SyncDriversAsync(List a_item) + { + await m_companyInfo.SyncDriverDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of CompanyDetails rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcompanydetails")] + public async Task SyncCompanyAsync(List a_item) + { + await m_companyInfo.SyncCompanyDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblUsers rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblusers")] + public async Task SyncUsersAsync(List a_item) + { + await m_users.SyncUserAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Trucks rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbltrucks")] + public async Task SyncTrucksAsync(List a_item) + { + await m_companyInfo.SyncTrucks(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblBranch rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblbranch")] + public async Task SyncBranchAsync(List a_item) + { + await m_companyInfo.SyncBranches(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCustomers rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcustomers")] + public async Task SyncCustomersAsync(List a_item) + { + await m_customer.SyncCustomers(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblTruck Inventory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbltruckinventory")] + public async Task SyncTruckInventoryAsync(List a_item) + { + await m_companyInfo.SyncTruckInventory(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblTruckAssignment rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblTruckAssignment")] + public async Task SyncTruckAssignmentSync(List a_item) + { + await m_companyInfo.SyncTruckAssignments(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblDriverMapping rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbldrivermappings")] + public async Task SyncTruckDriverMappingSync(List a_item) + { + await m_companyInfo.SyncTruckMappings(a_item); + } + } +} diff --git a/Cloud_Manager/Controllers/SyncControllers/SyncProductsController.cs b/Cloud_Manager/Controllers/SyncControllers/SyncProductsController.cs new file mode 100644 index 0000000..9deb571 --- /dev/null +++ b/Cloud_Manager/Controllers/SyncControllers/SyncProductsController.cs @@ -0,0 +1,144 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Cloud_Manager.Controllers.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncProductsController : ControllerBase + { + private readonly IProduct m_productService; + public SyncProductsController(IProduct a_productService) + { + m_productService = a_productService; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_productService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_productService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblProduct rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblProducts")] + public async Task SyncProductsAsync(List a_item) + { + await m_productService.SyncProducts(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInventory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblInventory")] + public async Task SyncInventoryAsync(List a_item) + { + await m_productService.SyncInventory(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Restock rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblRestock")] + public async Task SyncRestockAsync(List a_item) + { + await m_productService.SyncRestockAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInventoryEntries rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblInventoryentry")] + public async Task SyncInventoryEntriesAsync(List a_item) + { + await m_productService.SyncInventoryEntries(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of PriceChanges rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tlpricechanges")] + public async Task SyncPriceChangesAsync(List a_item) + { + await m_productService.SyncPriceChanges(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of ProductAltUnit rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblProductAltUnit")] + public async Task SyncProductAltUnitAsync(List a_item) + { + await m_productService.SyncProductAltUnit(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TbStock rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblStock")] + public async Task SyncStockAsync(List a_item) + { + await m_productService.SyncStockAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblBrands rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblbrands")] + public async Task SyncBrandsAsync(List a_item) + { + await m_productService.SyncBrandsAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCategory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCategories")] + public async Task SyncCategoriesAsync(List a_item) + { + await m_productService.SyncCategoriesAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of UnitOfMeasure rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblunitofmeasure")] + public async Task SyncUnitMeasureAsync(List a_item) + { + await m_productService.SyncUnitOfMeasureAsync(a_item); + } + } +} diff --git a/Cloud_Manager/Controllers/SyncControllers/SyncSalesController.cs b/Cloud_Manager/Controllers/SyncControllers/SyncSalesController.cs new file mode 100644 index 0000000..526a73e --- /dev/null +++ b/Cloud_Manager/Controllers/SyncControllers/SyncSalesController.cs @@ -0,0 +1,145 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace Cloud_Manager.Controllers.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncSalesController : ControllerBase + { + private readonly ISalesInterface m_salesService; + public SyncSalesController(ISalesInterface a_salesService) + { + m_salesService = a_salesService; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_salesService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCart rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCart")] + public async Task SyncSalesAsync(List a_item) + { + await m_salesService.SyncCart(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCancelledTransation rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcancelledtransaction")] + public async Task SyncCancelledTransactionAsync(List a_item) + { + await m_salesService.SyncCancelledTransaction(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInvoice rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblinvoice")] + public async Task SyncInvoiceAsync(List a_item) + { + await m_salesService.SyncInvoice(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of CreditPurchase rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCreditpurchase")] + public async Task SyncCreditPurchaseAsync(List a_item) + { + await m_salesService.SyncCreditPurchase(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Customer Account rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCustomerAccount")] + public async Task SyncCustomerAccountAsync(List a_item) + { + await m_salesService.SyncCustomerAccount(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Customer Purchase rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/CustomerPurchase")] + public async Task SyncCustomerPurchaseAsync(List a_item) + { + await m_salesService.SyncCustomerPurchase(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Discount logs rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/DiscountLogs")] + public async Task SyncDiscountLogsAsync(List a_item) + { + await m_salesService.SyncDiscountLogs(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Head rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliveryhead")] + public async Task SyncDeliveryHeadAsync(List a_item) + { + await m_salesService.SyncDeliveryHead(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Details rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliverydetails")] + public async Task SyncDeliveryDetailsAsync(List a_item) + { + await m_salesService.SyncDeliveryDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Recipient rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliveryrecipient")] + public async Task SyncDeliveryRecipientAsync(List a_item) + { + await m_salesService.SyncDeliveryRecipients(a_item); + } + } +} diff --git a/Cloud_Manager/Controllers/WeatherForecastController.cs b/Cloud_Manager/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..e5b1097 --- /dev/null +++ b/Cloud_Manager/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Cloud_Manager.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 _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable 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(); + } + } +} \ No newline at end of file diff --git a/Cloud_Manager/Models/ClientContractModels/Authtype.cs b/Cloud_Manager/Models/ClientContractModels/Authtype.cs new file mode 100644 index 0000000..4adbfcf --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Authtype.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Authtype +{ + public int Id { get; set; } + + public string? Type { get; set; } +} diff --git a/Cloud_Manager/Models/ClientContractModels/Clientbusiness.cs b/Cloud_Manager/Models/ClientContractModels/Clientbusiness.cs new file mode 100644 index 0000000..6b3b420 --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Clientbusiness.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Clientbusiness +{ + /// + /// there could be multiple branches of the same business + /// + public int BusinessId { get; set; } + + public int ClientId { get; set; } + + public string BusinessName { get; set; } = null!; + + public string BiskilogVersion { get; set; } = null!; + + public DateTime DateJoined { get; set; } + public string BusinessExternalId { get; set; } = string.Empty!; +} diff --git a/Cloud_Manager/Models/ClientContractModels/Clientinfo.cs b/Cloud_Manager/Models/ClientContractModels/Clientinfo.cs new file mode 100644 index 0000000..88eaedc --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Clientinfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Clientinfo +{ + public int ClientId { get; set; } + + public string? Fullname { get; set; } + + public string? PhoneNumber { get; set; } + + public string? Email { get; set; } +} diff --git a/Cloud_Manager/Models/ClientContractModels/Contract.cs b/Cloud_Manager/Models/ClientContractModels/Contract.cs new file mode 100644 index 0000000..e6fe6a2 --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Contract.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Contract +{ + public int ContractId { get; set; } + + public int ClientId { get; set; } + + public int? BusinessId { get; set; } + + public DateTime? StartDate { get; set; } + + public DateTime? EndDate { get; set; } + + public decimal? Bill { get; set; } + + public string Comments { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/ClientContractModels/Databasemap.cs b/Cloud_Manager/Models/ClientContractModels/Databasemap.cs new file mode 100644 index 0000000..969a985 --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Databasemap.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Databasemap +{ + public int DbNo { get; set; } + + public string DbName { get; set; } = null!; + + public int ClientId { get; set; } + public string Domain { get; set; } + + public DateTime LastSyncDate { get; set; } +} diff --git a/Cloud_Manager/Models/ClientContractModels/Siteaccesspermission.cs b/Cloud_Manager/Models/ClientContractModels/Siteaccesspermission.cs new file mode 100644 index 0000000..dc4c694 --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Siteaccesspermission.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Siteaccesspermission +{ + public int UserId { get; set; } + + /// + /// businessIds could also been seen as branchID + /// + public int BusinessId { get; set; } + + public int ClientId { get; set; } +} diff --git a/Cloud_Manager/Models/ClientContractModels/Userauth.cs b/Cloud_Manager/Models/ClientContractModels/Userauth.cs new file mode 100644 index 0000000..78813a7 --- /dev/null +++ b/Cloud_Manager/Models/ClientContractModels/Userauth.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.ClientContractModels; + +public partial class Userauth +{ + public int UserId { get; set; } + + public int ClientId { get; set; } + + public string? Username { get; set; } + + public string? Email { get; set; } + + public string? Passsword { get; set; } + + public string? PhoneNumber { get; set; } + + public int AuthType { get; set; } + + public ulong Isactive { get; set; } + + public ulong? Isowner { get; set; } + + public DateTime? LastLogin { get; set; } +} diff --git a/Cloud_Manager/Models/CustomModels/CancelledSales.cs b/Cloud_Manager/Models/CustomModels/CancelledSales.cs new file mode 100644 index 0000000..e7a2dcc --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/CancelledSales.cs @@ -0,0 +1,16 @@ +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class CancelledSales + { + public Tblcancelledtransaction? CancelledTransaction { get; set; } + public string Customer { get; set; } = "WALK-IN Purchase"; + public decimal? Value { get; set; } + } +} diff --git a/Cloud_Manager/Models/CustomModels/CustomerAccounts.cs b/Cloud_Manager/Models/CustomModels/CustomerAccounts.cs new file mode 100644 index 0000000..1218f1f --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/CustomerAccounts.cs @@ -0,0 +1,15 @@ +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class CustomerAccounts + { + public Tblcustomer Customer { get; set; } + public decimal Debt { get; set; } = 0; + } +} diff --git a/Cloud_Manager/Models/CustomModels/MostPurchaseItem.cs b/Cloud_Manager/Models/CustomModels/MostPurchaseItem.cs new file mode 100644 index 0000000..7bd528d --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/MostPurchaseItem.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class MostPurchasedItem + { + /// + /// Specifies the id of the product + /// + public string ProductId { get; set; } = string.Empty; + /// + /// Specifies the name of the product + /// + public string ProductName { get; set; } = string.Empty; + /// + /// The total revenue generated from the sale + /// + public decimal? Revenue { get; set; } + /// + /// This is the number of times the item has been sold + /// + public int? NbrTimesSold { get; set; } + + } +} diff --git a/Cloud_Manager/Models/CustomModels/ProductItem.cs b/Cloud_Manager/Models/CustomModels/ProductItem.cs new file mode 100644 index 0000000..82cf6b2 --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/ProductItem.cs @@ -0,0 +1,18 @@ +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class ProductItem + { + public Tblproduct? Product { get; set; } + public Tblinventory? Stock { get; set; } + public Restocklevel? Restocklevel { get; set; } + public List Units { get; set; } = new List(); + public string BaseUnit { get; set; } = string.Empty; + } +} diff --git a/Cloud_Manager/Models/CustomModels/ProductPriceChange.cs b/Cloud_Manager/Models/CustomModels/ProductPriceChange.cs new file mode 100644 index 0000000..2ab7f54 --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/ProductPriceChange.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class ProductPriceChange + { + public string? Pcode { get; set; } + public string? ProductName { get; set; } + public decimal? PreviousPrice { get; set; } + + public decimal? CurrentPrice { get; set; } + + public DateTime? ChangeDate { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; + } +} diff --git a/Cloud_Manager/Models/CustomModels/ProductUnits.cs b/Cloud_Manager/Models/CustomModels/ProductUnits.cs new file mode 100644 index 0000000..018c32a --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/ProductUnits.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class ProductUnits + { + public string? Pcode { get; set; } + + public string? UnitCode { get; set; } + public string? UnitName { get; set; } + + public string? UnitBarcode { get; set; } + + public decimal? PriceUnit { get; set; } + + public int? QuantityUnit { get; set; } + + public string DistinctiveCode { get; set; } = null!; + + public string BranchId { get; set; } = null!; + } +} diff --git a/Cloud_Manager/Models/CustomModels/SaleItem.cs b/Cloud_Manager/Models/CustomModels/SaleItem.cs new file mode 100644 index 0000000..0d861c4 --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/SaleItem.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class SaleItem + { + public string? Transno { get; set; } + + public DateTime? Date { get; set; } + + public string? Cashier { get; set; } + public string? Status { get; set; } + public decimal? Total { get; set; } + public string BranchId { get; set; } = null!; + + public string Customer { get; set; } = "Walk-In Purchase"!; + } +} diff --git a/Cloud_Manager/Models/CustomModels/SyncTimestamp.cs b/Cloud_Manager/Models/CustomModels/SyncTimestamp.cs new file mode 100644 index 0000000..7bdcc14 --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/SyncTimestamp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class SyncTimestamp + { + public string TableName { get; set; } + public DateTime Timestamp { get; set; } + } +} diff --git a/Cloud_Manager/Models/CustomModels/TradeSummary.cs b/Cloud_Manager/Models/CustomModels/TradeSummary.cs new file mode 100644 index 0000000..f9473d6 --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/TradeSummary.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class TradeSummary + { + public DateTime CurrentTradeDate { get; set; } = DateTime.Now; + public DateTime LastTradeDate { get; set; } = DateTime.Now.AddDays(-1); + public double CurrentTradeSales { get; set; } = 0; + public double LastTradeSales { get; set; } = 0; + } +} diff --git a/Cloud_Manager/Models/CustomModels/WeeklySaleItem.cs b/Cloud_Manager/Models/CustomModels/WeeklySaleItem.cs new file mode 100644 index 0000000..b599fdf --- /dev/null +++ b/Cloud_Manager/Models/CustomModels/WeeklySaleItem.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.CustomModels +{ + public class WeeklySaleItem + { + public DateTime Date { get; set; } + public decimal? Total { get; set; } + public string BranchId { get; set; } = null!; + } + + public class WeeklyCategorySummary + { + public decimal? Total { get; set; } + public string Category { get; set; } = string.Empty!; + } +} diff --git a/Cloud_Manager/Models/Enums/AuthEnums.cs b/Cloud_Manager/Models/Enums/AuthEnums.cs new file mode 100644 index 0000000..574b761 --- /dev/null +++ b/Cloud_Manager/Models/Enums/AuthEnums.cs @@ -0,0 +1,17 @@ +namespace Cloud_Manager.Models.Enums +{ + public enum AuthEnums + { + Registered, + AleadyLoggedin, + WrongPassword, + NotFound, + Found, + Expired, + Invalid, + Valid, + Successful, + Error + } +} + diff --git a/Cloud_Manager/Models/Enums/ConnectionEnums.cs b/Cloud_Manager/Models/Enums/ConnectionEnums.cs new file mode 100644 index 0000000..5ba0ea2 --- /dev/null +++ b/Cloud_Manager/Models/Enums/ConnectionEnums.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Enums +{ + public enum ConnectionEnums + { + ConnectionEstablished, + ConnectionNotEstablished, + } +} diff --git a/Cloud_Manager/Models/Interfaces/IAnalytics.cs b/Cloud_Manager/Models/Interfaces/IAnalytics.cs new file mode 100644 index 0000000..e4b31d6 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IAnalytics.cs @@ -0,0 +1,86 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.POSModels; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IAnalytics + { + /// + /// Fetches a collection of sales transaction made from the specified start date to the end date + /// + /// Specified Start Date + /// Specified end Date + /// + IEnumerable GetSalesTransaction(DateTime a_start, DateTime a_end); + /// + /// Fetches a collection of sales transaction made within a one week period + /// + /// + IEnumerable GetWeeklySalesTransaction(); + /// + /// Fetches a collection of in-debt customers + /// + IEnumerable GetInDebtCustomers(); + /// + /// Fetches a collection of Product Items which are currently out of stock + /// + /// + IEnumerable GetOutOfStockItems(); + /// + /// Fetches a collection of the most purchased Product Items within a specified date range + /// + /// + /// + /// + IEnumerable GetMostPurchasedItem(DateTime a_start, DateTime a_end); + /// + /// Fetches a collection of cancelled transaction within a specified date range + /// + /// + /// + /// + IEnumerable GetCancelledSales(DateTime a_start, DateTime a_end); + /// + /// Fetches a collection of transaction made by employees within a specified date range + /// + /// + /// + /// A dictionary of transactions made by employees with employee name as key + Dictionary> GetEmployeeSales(DateTime a_start, DateTime a_end); + /// + /// Fetches a collection of product price changes with a specified date range + /// + /// + /// + /// + IEnumerable GetPriceChanges(DateTime a_start, DateTime a_end); + /// + /// Fetch the trade summary which is made of the total sales made currently and previous trade + /// + /// + TradeSummary GetTradeSummary(); + /// + /// Fetches the most recent sales transactions + /// + /// The number of rows to return + /// + IEnumerable GetRecentSales(int a_limit); + /// + /// Fetches a collection of product price changes recently made + /// + /// the number of rows to return + /// + IEnumerable GetRecentPriceChanges(int a_limit); + /// + /// Fetches a collection of price change history per product + /// + /// the number of products to fetch history + /// + IEnumerable GetProductPriceChangeHistory(int a_limit); + /// + /// Fetches a collection of sales transaction grouped by category made within a one week period + /// + /// + IEnumerable GetWeeklySalesCategoryTransaction(int a_limit); + } +} diff --git a/Cloud_Manager/Models/Interfaces/IAuthService.cs b/Cloud_Manager/Models/Interfaces/IAuthService.cs new file mode 100644 index 0000000..8ced3a4 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IAuthService.cs @@ -0,0 +1,20 @@ +using Cloud_Manager.Models.ClientContractModels; +using Cloud_Manager.Models.ClientContractModels; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IAuthService + { + /// + /// Authenticates user or client + /// + /// + /// + /// A tokenized string with relevant information on the authenticated user + Task AuthenticateClient(string a_username, string a_password); + Contract? GetContract(int a_clientId, List a_businessId); + Databasemap GetClientDB(int a_clientId); + List GetSiteaccesspermission(int a_clientId, int a_userId); + List GetClientbusiness(int a_clientId, int userId); + } +} diff --git a/Cloud_Manager/Models/Interfaces/ICompanyInfo.cs b/Cloud_Manager/Models/Interfaces/ICompanyInfo.cs new file mode 100644 index 0000000..7c6350a --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/ICompanyInfo.cs @@ -0,0 +1,28 @@ +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface ICompanyInfo + { + IEnumerable FetchBranches(); + Task GetCompanyInfoAsync(); + Task> GetBranches(); + string GetCompanyName(); + string GetBranchName(string a_branchId); + Task SyncBranches(List a_branches); + Task SyncCompanyDetails(List a_details); + Task SyncDriverDetails(List a_details); + Task SyncSystemRoles(List a_roles); + Task SyncTrucks(List a_trucks); + Task SyncTruckAssignments(List a_assignments); + Task SyncTruckMappings(List a_mapping); + Task SyncTruckInventory(List a_inventories); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); + } +} diff --git a/Cloud_Manager/Models/Interfaces/IConnectionService.cs b/Cloud_Manager/Models/Interfaces/IConnectionService.cs new file mode 100644 index 0000000..1414764 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IConnectionService.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IConnectionService + { + /// + /// Prepares and returns the connection string for a client using the specified database id + /// + /// Specified database id to use + /// + string GetClientConnectionString(int a_databaseId); + /// + /// Prepare the DB context from the specified connection string + /// + /// + /// A configured BiskAcdbContext + object PrepareDBContext(string a_connectionString); + } +} diff --git a/Cloud_Manager/Models/Interfaces/ICustomer.cs b/Cloud_Manager/Models/Interfaces/ICustomer.cs new file mode 100644 index 0000000..c23931e --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/ICustomer.cs @@ -0,0 +1,12 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.POSModels; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface ICustomer + { + IEnumerable FetchCustomers(); + Task> GetCustomers(); + Task SyncCustomers(List a_details); + } +} diff --git a/Cloud_Manager/Models/Interfaces/IMainInterface.cs b/Cloud_Manager/Models/Interfaces/IMainInterface.cs new file mode 100644 index 0000000..4d18434 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IMainInterface.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IMainInterface + { + void ShowReceipt(string a_receipt); + DateOnly CurrentTradeDate(); + DateOnly PreviousTradeDate(); + } +} diff --git a/Cloud_Manager/Models/Interfaces/IProducts.cs b/Cloud_Manager/Models/Interfaces/IProducts.cs new file mode 100644 index 0000000..9768d01 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IProducts.cs @@ -0,0 +1,44 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IProduct + { + IEnumerable GetUnitofmeasures(); + IEnumerable GetProducts(string a_productKey = ""); + IEnumerable GetBrands(string a_brandKey = ""); + IEnumerable GetCategories(string a_categoryKey = ""); + IEnumerable GetLowstockItems(); + Task FetchProducts(); + Task FetchLowStockProducts(); + Task FetchUnits(); + Task FetchBrands(); + Task FetchCategories(); + void RefreshList(); + ProductItem GetProductById(string a_id); + ProductItem GetProductByName(string name); + string GetUnitName(string a_unitCode); + event EventHandler ProductsChanged; + event EventHandler UnitsChanged; + event EventHandler BrandsChanged; + event EventHandler CategoriesChanged; + Task SyncProducts(List a_item); + Task SyncInventory(List a_item); + Task SyncInventoryEntries(List a_item); + Task SyncPriceChanges(List a_items); + Task SyncProductAltUnit(List a_items); + Task SyncRestockAsync(List a_items); + Task SyncUnitOfMeasureAsync(List a_items); + Task SyncStockAsync(List a_items); + Task SyncBrandsAsync(List a_items); + Task SyncCategoriesAsync(List a_items); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); + } +} diff --git a/Cloud_Manager/Models/Interfaces/ISalesHub.cs b/Cloud_Manager/Models/Interfaces/ISalesHub.cs new file mode 100644 index 0000000..a552406 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/ISalesHub.cs @@ -0,0 +1,10 @@ +using Cloud_Manager.Models.CustomModels; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface ISalesHub + { + Task TransactionMade(SaleItem a_transaction); + Task JoinCompanyGroup(); + } +} diff --git a/Cloud_Manager/Models/Interfaces/ISalesInterface.cs b/Cloud_Manager/Models/Interfaces/ISalesInterface.cs new file mode 100644 index 0000000..5968319 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/ISalesInterface.cs @@ -0,0 +1,36 @@ +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface ISalesInterface + { + Task FetchRecentTransaction(int a_limit); + Task FetchTransaction(DateTime a_start, DateTime a_end); + IEnumerable GetTransactions(DateTime a_start, DateTime a_end); + IEnumerable GetRecentTransaction(); + Task FetchReceipt(string a_receiptId); + IEnumerable GetReceipt(string a_receiptId); + Task> GetReceiptDetail(string a_receiptId); + Task SyncCart(List a_item); + Task SyncCancelledTransaction(List a_item); + Task SyncCreditPurchase(List a_item); + Task SyncCustomerAccount(List a_customerAccounts); + Task SyncCustomerPurchase(List a_customerPurchase); + Task SyncDiscountLogs(List a_discountLog); + Task SyncDeliveryDetails(List a_details); + Task SyncDeliveryHead(List a_heads); + Task SyncDeliveryRecipients(List a_recipients); + Task SyncInvoice(List a_invoice); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); + event EventHandler TransactionsChanged; + event EventHandler FetchComplete; + event EventHandler FetchStart; + } +} diff --git a/Cloud_Manager/Models/Interfaces/ITokenService.cs b/Cloud_Manager/Models/Interfaces/ITokenService.cs new file mode 100644 index 0000000..c8c9c2d --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/ITokenService.cs @@ -0,0 +1,18 @@ +using Cloud_Manager.Models.ClientContractModels; +using Cloud_Manager.Models.Enums; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface ITokenService + { + AuthEnums ValidateToken(string a_token); + string GenerateToken(Userauth a_user, Contract a_clientContract, Databasemap a_database, List a_business, bool a_comparison); + int? GetDatabaseIdFromToken(string a_token); + int? GetUserIdFromToken(string a_token); + string? GetUserNameFromToken(string a_token); + string? GetBaseBranch(string a_token); + bool? GetComparison(string a_token); + IEnumerable BranchIds(string a_token); + string? GetAllBranch(string a_token); + } +} diff --git a/Cloud_Manager/Models/Interfaces/IUser.cs b/Cloud_Manager/Models/Interfaces/IUser.cs new file mode 100644 index 0000000..e4134c7 --- /dev/null +++ b/Cloud_Manager/Models/Interfaces/IUser.cs @@ -0,0 +1,16 @@ +using Cloud_Manager.Models.POSModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cloud_Manager.Models.Interfaces +{ + public interface IUser + { + IEnumerable FetchUsers(); + Task> GetUsers(); + Task SyncUserAsync(List a_users); + } +} diff --git a/Cloud_Manager/Models/POSModels/Creditpurchase.cs b/Cloud_Manager/Models/POSModels/Creditpurchase.cs new file mode 100644 index 0000000..80015de --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Creditpurchase.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Creditpurchase +{ + public string ReceiptId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public DateTime Date { get; set; } + + public decimal TotalBill { get; set; } + + public decimal Paid { get; set; } + + public string CustomerId { get; set; } = null!; + + public string Status { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Customeraccount.cs b/Cloud_Manager/Models/POSModels/Customeraccount.cs new file mode 100644 index 0000000..88f6f94 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Customeraccount.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Customeraccount +{ + public string CustomerId { get; set; } = null!; + + public string TransactionId { get; set; } = null!; + + public DateTime Date { get; set; } + + public decimal Debit { get; set; } + + public decimal Credit { get; set; } + + public decimal Balance { get; set; } + + public string Comments { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Productaltunit.cs b/Cloud_Manager/Models/POSModels/Productaltunit.cs new file mode 100644 index 0000000..9a5abdc --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Productaltunit.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Productaltunit +{ + public string? Pcode { get; set; } + + public string? UnitCode { get; set; } + + public string? UnitBarcode { get; set; } + + public decimal? PriceUnit { get; set; } + + public int? QuantityUnit { get; set; } + + public string DistinctiveCode { get; set; } = null!; + + public string BranchId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Restocklevel.cs b/Cloud_Manager/Models/POSModels/Restocklevel.cs new file mode 100644 index 0000000..1f51ab0 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Restocklevel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Restocklevel +{ + public string ProductId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public int? WarnLevel { get; set; } + + public string? Unit { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Systemuserrole.cs b/Cloud_Manager/Models/POSModels/Systemuserrole.cs new file mode 100644 index 0000000..d26f693 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Systemuserrole.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Systemuserrole +{ + public string? Roles { get; set; } + + public bool? Owner { get; set; } + + public bool? Manager { get; set; } + + public bool? Assist { get; set; } + + public bool? Cashier { get; set; } + + public int Id { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblbranch.cs b/Cloud_Manager/Models/POSModels/Tblbranch.cs new file mode 100644 index 0000000..4a37868 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblbranch.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblbranch +{ + public string? BranchName { get; set; } + + public string BranchId { get; set; } = null!; + + public string? Address { get; set; } + + public string? City { get; set; } + + public string? StateOrProvince { get; set; } + + public string? BranchTelephone { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblbrand.cs b/Cloud_Manager/Models/POSModels/Tblbrand.cs new file mode 100644 index 0000000..a805dda --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblbrand.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblbrand +{ + public string Id { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Brand { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblcancelledtransaction.cs b/Cloud_Manager/Models/POSModels/Tblcancelledtransaction.cs new file mode 100644 index 0000000..c08f411 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcancelledtransaction.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcancelledtransaction +{ + public string? Transno { get; set; } + + public DateTime? DateCancelled { get; set; } + + public string? CancelledBy { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblcart.cs b/Cloud_Manager/Models/POSModels/Tblcart.cs new file mode 100644 index 0000000..5cab7e6 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcart.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcart +{ + public string? Transno { get; set; } + + public string? Id { get; set; } + + public int? Quantity { get; set; } + + public DateTime? Date { get; set; } + + public decimal? Price { get; set; } + + public string? Cashier { get; set; } + + public string? Status { get; set; } + + public decimal? Total { get; set; } + + public string? Unit { get; set; } + public decimal? Tendered { get; set; } + public decimal? Balance { get; set; } + public decimal? ValueAddTax { get; set; } + public decimal? Discount { get; set; } = 0; + + public decimal? Costprice { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblcategory.cs b/Cloud_Manager/Models/POSModels/Tblcategory.cs new file mode 100644 index 0000000..bb36651 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcategory.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcategory +{ + public string Id { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Category { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblcompanydetail.cs b/Cloud_Manager/Models/POSModels/Tblcompanydetail.cs new file mode 100644 index 0000000..16ff2b0 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcompanydetail.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcompanydetail +{ + public string? CompanyName { get; set; } + + public string? Address { get; set; } + + public string? Website { get; set; } + + public string? Email { get; set; } + + public string Tin { get; set; } = null!; + + public string? MainTelephone { get; set; } + + public string? Vatno { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblcustomer.cs b/Cloud_Manager/Models/POSModels/Tblcustomer.cs new file mode 100644 index 0000000..fbf73a7 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcustomer.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcustomer +{ + public string CustomerId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Firstname { get; set; } + + public string? Surname { get; set; } + + public string? Address { get; set; } + + public string? Telephone { get; set; } + + public DateTime? DateAdded { get; set; } + + public string? Status { get; set; } + + public string? Tin { get; set; } + + public DateTime? DateExit { get; set; } + + public string? Email { get; set; } + + public string? FinancialStatus { get; set; } + + public string? NameKey1 { get; set; } + + public string? NameKey2 { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblcustomerpurchase.cs b/Cloud_Manager/Models/POSModels/Tblcustomerpurchase.cs new file mode 100644 index 0000000..9c02f35 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblcustomerpurchase.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblcustomerpurchase +{ + public string? CustomerId { get; set; } + + public string? TransactionId { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbldeliverydetail.cs b/Cloud_Manager/Models/POSModels/Tbldeliverydetail.cs new file mode 100644 index 0000000..4ce7dd9 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbldeliverydetail.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbldeliverydetail +{ + public string? DeliveryId { get; set; } + + public string? Pcode { get; set; } + + public int? Quantity { get; set; } + + public string? Unit { get; set; } + + public decimal? Cost { get; set; } + + public string CountId { get; set; } = null!; + + public string BranchId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbldeliveryhead.cs b/Cloud_Manager/Models/POSModels/Tbldeliveryhead.cs new file mode 100644 index 0000000..e09203a --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbldeliveryhead.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbldeliveryhead +{ + public string DeliveryId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? GeneratedBy { get; set; } + + public DateTime? DateInitiated { get; set; } + + public DateTime? DateCompleted { get; set; } + + public string? Destination { get; set; } + + public string? CustomerId { get; set; } + + public decimal? TotalCost { get; set; } + + public string? Status { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tbldeliveryrecipient.cs b/Cloud_Manager/Models/POSModels/Tbldeliveryrecipient.cs new file mode 100644 index 0000000..3840cd3 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbldeliveryrecipient.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbldeliveryrecipient +{ + public string DeliveryId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Fullname { get; set; } + + public string? Address { get; set; } + + public string? Telephone { get; set; } + + public string? Email { get; set; } + + public string? CustomerId { get; set; } + + public DateOnly? FromDate { get; set; } + + public DateOnly? ToDate { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tbldiscountlog.cs b/Cloud_Manager/Models/POSModels/Tbldiscountlog.cs new file mode 100644 index 0000000..5de6191 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbldiscountlog.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbldiscountlog +{ + public string? ReceiptId { get; set; } + + public string? Cashier { get; set; } + + public DateTime? Date { get; set; } + + public decimal? Discount { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbldriver.cs b/Cloud_Manager/Models/POSModels/Tbldriver.cs new file mode 100644 index 0000000..9d5bd2c --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbldriver.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbldriver +{ + public string DriverId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Firstname { get; set; } + + public string? Surname { get; set; } + + public string? Middlename { get; set; } + + public DateOnly? DateOfBirth { get; set; } + + public string? Address1 { get; set; } + + public string? Address2 { get; set; } + + public string? Telephone { get; set; } + + public string? Email { get; set; } + + public string? City { get; set; } + + public string? State { get; set; } + + public string? Status { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tblinventory.cs b/Cloud_Manager/Models/POSModels/Tblinventory.cs new file mode 100644 index 0000000..b8ec57c --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblinventory.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblinventory +{ + public string? Pcode { get; set; } + + public int? Quantity { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblinventoryentry.cs b/Cloud_Manager/Models/POSModels/Tblinventoryentry.cs new file mode 100644 index 0000000..1b4a522 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblinventoryentry.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblinventoryentry +{ + public string? Pcode { get; set; } + + public int? Quantity { get; set; } + + public DateTime? Date { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblinvoice.cs b/Cloud_Manager/Models/POSModels/Tblinvoice.cs new file mode 100644 index 0000000..649a271 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblinvoice.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblinvoice +{ + public string? InvoiceId { get; set; } + + public string? Pcode { get; set; } + + public int? Quantity { get; set; } + + public decimal? Unitprice { get; set; } + + public string? Unit { get; set; } + + public decimal? Totalprice { get; set; } + + public DateOnly? DateGenerated { get; set; } + + public string? Status { get; set; } + + public string? GeneratedBy { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblpricechange.cs b/Cloud_Manager/Models/POSModels/Tblpricechange.cs new file mode 100644 index 0000000..5bc48dc --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblpricechange.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblpricechange +{ + public string? Pcode { get; set; } + + public decimal? PreviousPrice { get; set; } + + public decimal? CurrentPrice { get; set; } + + public DateTime? ChangeDate { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblproduct.cs b/Cloud_Manager/Models/POSModels/Tblproduct.cs new file mode 100644 index 0000000..e47b19a --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblproduct.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tblproduct +{ + public string? Pcode { get; set; } + + public string? Barcode { get; set; } + + public string? Pdesc { get; set; } + + public string? Bid { get; set; } + + public string? Cid { get; set; } + + public decimal? Price { get; set; } + + public decimal? Costprice { get; set; } + + public string? BaseUnit { get; set; } + + public string? ProductName { get; set; } + + public string? Status { get; set; } + + public string BranchId { get; set; } = null!; + + public string CountId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tblsyncinfo.cs b/Cloud_Manager/Models/POSModels/Tblsyncinfo.cs new file mode 100644 index 0000000..59f8194 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tblsyncinfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Biskilog_Accounting.Server.POSModels; + +public partial class Tblsyncinfo +{ + public string TableName { get; set; } = null!; + + public DateTime? LastSyncDate { get; set; } = DateTime.MinValue; + + public string? BranchId { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tbltruck.cs b/Cloud_Manager/Models/POSModels/Tbltruck.cs new file mode 100644 index 0000000..e583062 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbltruck.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbltruck +{ + public string TruckId { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? LicensePlate { get; set; } + + public string? Brand { get; set; } + + public string? Driver { get; set; } + + public decimal? Weight { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/TbltruckDrivermapping.cs b/Cloud_Manager/Models/POSModels/TbltruckDrivermapping.cs new file mode 100644 index 0000000..7ce5471 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/TbltruckDrivermapping.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class TbltruckDrivermapping +{ + public string? TruckId { get; set; } + + public string? DriverId { get; set; } + + public DateTime? DateEntry { get; set; } + + public string? Operation { get; set; } + + public string CountId { get; set; } = null!; + + public string BranchId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbltruckassignment.cs b/Cloud_Manager/Models/POSModels/Tbltruckassignment.cs new file mode 100644 index 0000000..3f0c83f --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbltruckassignment.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbltruckassignment +{ + public string? OrderId { get; set; } + + public decimal? Cost { get; set; } + + public string? TruckId { get; set; } + + public string? Status { get; set; } + + public DateTime? DateAssigned { get; set; } + + public string CountId { get; set; } = null!; + + public string BranchId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbltruckinventory.cs b/Cloud_Manager/Models/POSModels/Tbltruckinventory.cs new file mode 100644 index 0000000..f751e70 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbltruckinventory.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbltruckinventory +{ + public string? TruckId { get; set; } + + public string? Pcode { get; set; } + + public int? Quantity { get; set; } + + public string? Unit { get; set; } + + public string CountId { get; set; } = null!; + + public string BranchId { get; set; } = null!; +} diff --git a/Cloud_Manager/Models/POSModels/Tbluser.cs b/Cloud_Manager/Models/POSModels/Tbluser.cs new file mode 100644 index 0000000..3902117 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbluser.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbluser +{ + public string Username { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Password { get; set; } = string.Empty; + + public string? Firstname { get; set; } = string.Empty; + + public string? Surname { get; set; } = string.Empty; + + public string? StreetAddress1 { get; set; } = string.Empty; + + public string? StreetAddress2 { get; set; } = string.Empty; + + public string? City { get; set; } = string.Empty; + + public string? StateOrProvince { get; set; } = string.Empty; + + public string? Telephone { get; set; } = string.Empty; + + public string? Email { get; set; } + + public string? AccessLevel { get; set; } + + public DateTime? LastLogin { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Tbstock.cs b/Cloud_Manager/Models/POSModels/Tbstock.cs new file mode 100644 index 0000000..4a11567 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Tbstock.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Tbstock +{ + public string? Refno { get; set; } + + public string? Pcode { get; set; } + + public int? Qty { get; set; } + + public DateTime? Sdate { get; set; } + + public string? Stockinby { get; set; } + + public string? BranchId { get; set; } + + public string CountId { get; set; } = null!; + + public DateTime LastModified { get; set; } +} diff --git a/Cloud_Manager/Models/POSModels/Unitofmeasure.cs b/Cloud_Manager/Models/POSModels/Unitofmeasure.cs new file mode 100644 index 0000000..f9b6e64 --- /dev/null +++ b/Cloud_Manager/Models/POSModels/Unitofmeasure.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace Cloud_Manager.Models.POSModels; + +public partial class Unitofmeasure +{ + public string UnitCode { get; set; } = null!; + + public string BranchId { get; set; } = null!; + + public string? Unitname { get; set; } + + public string? Unitshort { get; set; } + + public string? Status { get; set; } +} diff --git a/Cloud_Manager/Models/ServiceRepo/TokenService.cs b/Cloud_Manager/Models/ServiceRepo/TokenService.cs new file mode 100644 index 0000000..8eef96b --- /dev/null +++ b/Cloud_Manager/Models/ServiceRepo/TokenService.cs @@ -0,0 +1,199 @@ +using Cloud_Manager.Models.ClientContractModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace Cloud_Manager.Models.ServiceRepo +{ + public class TokenService : ITokenService + { + private IConfiguration m_configuration { get; } + public TokenService(IConfiguration a_configuration) + { + m_configuration = a_configuration; + } + + /// + /// Validates a user access token + /// + /// AuthEnums.Valid if token is a valid and unexpired token + public AuthEnums ValidateToken(string a_token) + { + try + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + + if (jwtToken.ValidFrom <= DateTime.Now && jwtToken.ValidTo > DateTime.Now) + return AuthEnums.Valid; + return AuthEnums.Expired; + } + catch (Exception ex) + { + return AuthEnums.Invalid; + } + } + /// + /// Generates an access token based on the user + /// + /// A tokenized string + public string GenerateToken(Userauth a_user, Contract a_clientContract, Databasemap a_database, List a_business, bool a_comparison) + { + try + { + //create claims details based on the user information + var claims = new[] { + new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), + new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString()), + new Claim("ContractStart",a_clientContract.StartDate !.Value.ToString()), + new Claim("ContractEnd",a_clientContract.EndDate!.Value.ToString()), + new Claim("UserId", a_user.UserId.ToString()), + new Claim("Username", a_user.Username.ToString()), + new Claim("DbId",a_database.DbNo.ToString()), + new Claim("ComparisonMode",a_comparison.ToString()), + new Claim("BranchId",a_business[0].ToString()), + new Claim("BranchAccess",string.Join(", ", a_business.ToArray())), + new Claim("ClientId", a_user.ClientId.ToString()), + }; + + var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(m_configuration["Jwt:Key"]!)); + + var signIn = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + + var token = new JwtSecurityToken(m_configuration["Jwt:Issuer"], m_configuration["Jwt:Audience"], claims, expires: DateTime.UtcNow.AddDays(14), signingCredentials: signIn); + return $"{new JwtSecurityTokenHandler().WriteToken(token)}"; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return AuthEnums.Error.ToString(); + } + } + /// + ///Deserializes the token string if valid to return the specified user role id in the token string + /// + /// + /// RoleId + public int? GetDatabaseIdFromToken(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return int.Parse(jwtToken.Claims.First(claim => claim.Type == "DbId").Value); + } + return null; + } + /// + ///Deserializes the token string if valid to return the specified user id in the token string + /// + /// + /// UserId + public int? GetUserIdFromToken(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return int.Parse(jwtToken.Claims.First(claim => claim.Type == "UserId").Value); + } + return null; + } + /// + ///Deserializes the token string if valid to return the specified username in the token string + /// + /// + /// Username + public string? GetUserNameFromToken(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return jwtToken.Claims.First(claim => claim.Type == "Username").Value; + } + return null; + } + /// + ///Deserializes the token string if valid to return the specified branchId in the token string + /// + /// + /// Username + public string? GetBaseBranch(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return jwtToken.Claims.First(claim => claim.Type == "BranchId").Value; + } + return null; + } + + public bool? GetComparison(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return bool.Parse(jwtToken.Claims.First(claim => claim.Type == "ComparisonMode").Value); + } + return null; + } + /// + ///Deserializes the token string if valid to return the specified list of branches a user has access to in the token string + /// + /// + /// Username + public string? GetAllBranch(string a_token) + { + if (ValidateToken(a_token) == AuthEnums.Valid) + { + string token = a_token.Substring(6).Trim(); + var handler = new JwtSecurityTokenHandler(); + JwtSecurityToken jwtToken = (JwtSecurityToken)handler.ReadToken(token); + return jwtToken.Claims.First(claim => claim.Type == "BranchAccess").Value; + } + return null; + } + /// + /// Return a specified list of branches a user has access if comparison mode is set otherwise returns only the + /// active branch on the list + /// + /// + /// + public IEnumerable BranchIds(string a_token) + { + List branchIds = new List(); + if (ValidateToken(a_token) == AuthEnums.Valid) + { + bool comparison = GetComparison(a_token)!.Value; + if (comparison) + { + string? branches = GetAllBranch(a_token); + if (branches != null) + { + string[] branchArray = branches!.Split(); + branchIds.AddRange(branchArray); + } + } + else + { + string? baseBranch = GetBaseBranch(a_token); + branchIds.Add(baseBranch!); + } + } + return branchIds.AsEnumerable(); + } + } +} diff --git a/Cloud_Manager/Program.cs b/Cloud_Manager/Program.cs new file mode 100644 index 0000000..a7e0963 --- /dev/null +++ b/Cloud_Manager/Program.cs @@ -0,0 +1,103 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using System.Text.Json.Serialization; +using System.Text; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager; +using Cloud_Manager.Services; +using Cloud_Manager.Models.ServiceRepo; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddSignalR(); +builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles); +builder.Logging.ClearProviders(); +builder.Logging.AddConsole(); +builder.Services.AddEntityFrameworkMySql().AddDbContext(options => +{ + options.UseMySql(builder.Configuration.GetConnectionString("Connection"), new MariaDbServerVersion(new Version())); +}); +builder.Services.AddSingleton(); +builder.Services.AddDbContext(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +//builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => +//{ +// options.RequireHttpsMetadata = false; +// options.SaveToken = true; +// options.TokenValidationParameters = new TokenValidationParameters() +// { +// ValidateIssuer = true, +// ValidateAudience = true, +// ValidAudience = builder.Configuration["Jwt:Audience"], +// ValidIssuer = builder.Configuration["Jwt:Issuer"], +// IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])) +// }; +//}); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyBlazor", Version = "v1" }); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please enter a valid token", + Name = "Authorization", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT", + Scheme = "Bearer" + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type=ReferenceType.SecurityScheme, + Id="Bearer" + } + }, + new string[]{} + } + }); +}); +builder.Services.AddControllersWithViews(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyBlazor v1"); + c.RoutePrefix = "api/docs"; + }); +} +else +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} +app.UseHttpsRedirection(); + +app.UseRouting(); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Cloud_Manager/Properties/launchSettings.json b/Cloud_Manager/Properties/launchSettings.json new file mode 100644 index 0000000..72127dd --- /dev/null +++ b/Cloud_Manager/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57096", + "sslPort": 44350 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5232", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7122;http://localhost:5232", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Cloud_Manager/Services/AuthenticationService.cs b/Cloud_Manager/Services/AuthenticationService.cs new file mode 100644 index 0000000..2591a9c --- /dev/null +++ b/Cloud_Manager/Services/AuthenticationService.cs @@ -0,0 +1,146 @@ +using Cloud_Manager; +using Cloud_Manager.Models.ClientContractModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace Cloud_Manager.Services +{ + public class AuthenticationService : IAuthService + { + private readonly BiskilogContext m_context; + private readonly ITokenService m_tokenService; + + public AuthenticationService(BiskilogContext a_context, ITokenService a_tokenService) + { + m_context = a_context; + m_tokenService = a_tokenService; + } + + /// + /// Returns the status of a user account + /// + /// AuthEnums + public AuthEnums AccountStatus(int? a_id, string? a_username) + { + if (m_context.Userauths.Any(i => i.UserId == a_id || i.Username == a_username)) + { + return AuthEnums.Found; + } + else + { + return AuthEnums.NotFound; + } + } + /// + /// Autenticates a user and returns a tokenized string + /// + /// + /// + /// strings + + public async Task AuthenticateClient(string a_username, string a_password) + { + var user = await GetUserAsync(a_username, a_password); + + if (user == null) + { + return null; + } + user.LastLogin = DateTime.Now; + m_context.Userauths.Update(user); + m_context.SaveChanges(); + + + Databasemap databasemap = GetClientDB(user.ClientId); + + List businessIds = GetSiteaccesspermission(user.ClientId, user.UserId).Select(t => t.BusinessId).ToList(); + Contract? contract = GetContract(user.ClientId, businessIds); + List businesses = GetClientbusiness(user.ClientId, user.UserId).Select(t => t.BusinessExternalId).ToList(); + + if (contract == null) + return AuthEnums.Invalid.ToString(); + + return m_tokenService.GenerateToken(user, contract, databasemap, businesses, false); + } + + /// + /// Creates a new user account + /// + /// returns AuthEnums.successful if the account was created successfully + public AuthEnums CreateUser(Userauth a_user) + { + throw new NotImplementedException(); + //if (AccountStatus(null, a_user.Username) == AuthEnums.Found) + // return AuthEnums.Registered; + + //a_user.Role = m_context.UserRoles.First(i => i.RoleId== a_user.RoleId); + //a_user.Password = BCrypt.Net.BCrypt.HashPassword(a_user.Password); + //m_context.Users.Add(a_user); + + //var result = m_context.SaveChangesAsync(); + //result.Wait(); + //if(result.Result > 0) + //{ + // return AuthEnums.Successful; + //} + //return AuthEnums.Error; + } + + /// + /// Deletes a user account + /// + /// + public void DeleteUser(int a_id) + { + throw new NotImplementedException(); + } + + public List GetClientbusiness(int a_clientId, int userId) + { + return (from b in m_context.Clientbusinesses + join p in m_context.Siteaccesspermissions on new { b.ClientId, b.BusinessId } equals new { p.ClientId, p.BusinessId } + where p.UserId == userId && p.ClientId == a_clientId + select b).ToList(); + } + + public Databasemap GetClientDB(int a_clientId) + { + return m_context.Databasemaps.First(t => t.ClientId == a_clientId); + } + + public Contract? GetContract(int a_clientId, List a_businessId) + { + return m_context.Contracts.FirstOrDefault(c => c.ClientId == a_clientId && a_businessId.Contains(c.BusinessId!.Value) && c.EndDate >= DateTime.Now); + } + + public List GetSiteaccesspermission(int a_clientId, int a_userId) + { + return m_context.Siteaccesspermissions.Where(t => t.ClientId == a_clientId && t.UserId == a_userId).ToList(); + } + + private async Task GetUserAsync(string username, string password) + { + //Todo have complete implementation after means of creating user is done + //try + //{ + // string pa = await m_context.Userauths.Where(u => u.Username == username).Select(u => u.Password).FirstAsync(); + // bool verified = BCrypt.Net.BCrypt.Verify(password, pa); + // if (verified) + // { + + //TODO have a complete implementation + return await m_context.Userauths.FirstAsync(u => u.Username == username && u.Passsword == password); + // } + // else + // { + // return null; + // } + //}catch(Exception ex) + //{ + // //possible is user not found + // return null; + //} + } + } +} diff --git a/Cloud_Manager/Services/CompanyService.cs b/Cloud_Manager/Services/CompanyService.cs new file mode 100644 index 0000000..13cc9fe --- /dev/null +++ b/Cloud_Manager/Services/CompanyService.cs @@ -0,0 +1,227 @@ +using Cloud_Manager; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Text.Json; + +namespace Cloud_Manager.Services +{ + public class CompanyService : ICompanyInfo + { + private readonly BiskAcdbContext m_context; + private readonly ITokenService m_tokenService; + private readonly HttpContext m_httpContext; + + private Tblcompanydetail m_companyInfo { get; set; } + private IEnumerable m_companyBranches { get; set; } + public CompanyService(BiskAcdbContext a_context, ITokenService a_tokenService, IHttpContextAccessor a_httpContextAccessor) + { + m_context = a_context; + m_tokenService = a_tokenService; + m_httpContext = a_httpContextAccessor?.HttpContext; + m_companyInfo = new Tblcompanydetail(); + m_companyBranches = new List(); + + GetCompanyInfoAsync(); + GetBranches(); + } + public IEnumerable FetchBranches() + { + return m_companyBranches; + } + + public async Task> GetBranches() + { + m_companyBranches = m_context.Tblbranches; + return await Task.FromResult(m_companyBranches); + } + + public string GetBranchName(string a_branchId) + { + return m_companyBranches.FirstOrDefault(b => b.BranchId == a_branchId).BranchName; + } + + public Task GetCompanyInfoAsync() + { + m_companyInfo = m_context.Tblcompanydetails.FirstOrDefault(); + return Task.FromResult(m_companyInfo); + } + + public string GetCompanyName() + { + return m_companyInfo.CompanyName; + } + public async Task SyncBranches(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL BranchSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000, 01, 01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } + + public async Task SyncSystemRoles(List a_roles) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_roles); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SystemUserRolesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public async Task SyncCompanyDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CompanyDetailSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDriverDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DriverSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTrucks(List a_trucks) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_trucks); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckAssignments(List a_assignments) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_assignments); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckAssignmentSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckMappings(List a_mapping) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_mapping); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckDriverMappingSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckInventory(List a_inventories) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_inventories); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckInventorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + } +} diff --git a/Cloud_Manager/Services/ConnectionService.cs b/Cloud_Manager/Services/ConnectionService.cs new file mode 100644 index 0000000..2e3108c --- /dev/null +++ b/Cloud_Manager/Services/ConnectionService.cs @@ -0,0 +1,50 @@ +using Cloud_Manager; +using Cloud_Manager.Models.ClientContractModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; + +namespace Cloud_Manager.Services +{ + public class ConnectionService : IConnectionService + { + private readonly BiskilogContext m_context; + private readonly IConfiguration m_configuration; + + public ConnectionService(BiskilogContext a_context, IConfiguration configuration) + { + m_context = a_context; + m_configuration = configuration; + } + /// + /// Prepares and returns the connection string for a client using the specified database id + /// + /// Specified database id to use + /// + public string GetClientConnectionString(int a_databaseId) + { + Databasemap? dbMap = m_context.Databasemaps.Find(a_databaseId); + if (dbMap != null) + { + string rawConString = m_configuration.GetConnectionString("PrivateConnection")!.ToString(); + return string.Format(rawConString, dbMap.Domain, dbMap.DbName); + } + return ConnectionEnums.ConnectionNotEstablished.ToString(); + } + /// + /// Prepare the DB context from the specified connection string + /// + /// + /// + /// A configured BiskAcdbContext + public object PrepareDBContext(string a_connectionString) + { + throw new NotImplementedException(); + //DbContextOptionsBuilder acdbContext = new DbContextOptionsBuilder(); + //acdbContext.UseMySql(a_connectionString, new MariaDbServerVersion(new Version())); + + //return new BiskAcdbContext(acdbContext.Options); + } + } +} diff --git a/Cloud_Manager/Services/CustomerService.cs b/Cloud_Manager/Services/CustomerService.cs new file mode 100644 index 0000000..aac20cb --- /dev/null +++ b/Cloud_Manager/Services/CustomerService.cs @@ -0,0 +1,89 @@ +using Cloud_Manager; +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Text.Json; + +namespace Cloud_Manager.Services +{ + public class CustomerService : ICustomer + { + private readonly BiskAcdbContext m_context; + private readonly ITokenService m_tokenService; + private readonly HttpContext m_httpContext; + + public CustomerService(BiskAcdbContext a_context, ITokenService a_tokenService, IHttpContextAccessor a_httpContextAccessor) + { + m_context = a_context; + m_tokenService = a_tokenService; + m_httpContext = a_httpContextAccessor?.HttpContext; + } + public IEnumerable FetchCustomers() + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetCustomers(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", string.Join(", ", accessiblebranches.ToArray()))); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + yield return new CustomerAccounts + { + Customer = new Tblcustomer + { + CustomerId = reader.GetString(0), + BranchId = reader.GetString(1), + Firstname = reader.GetString(2), + Surname = reader.GetString(3), + Address = reader.GetString(4), + Telephone = reader.GetString(5), + DateAdded = reader.GetDateTime(6), + Status = reader.GetString(7), + Email = reader.GetString(8), + FinancialStatus = reader.GetString(9), + }, + Debt = reader.GetDecimal(10) + }; + } + } + } + } + } + + public Task> GetCustomers() + { + throw new NotImplementedException(); + } + + public async Task SyncCustomers(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + } +} diff --git a/Cloud_Manager/Services/ProductRepo.cs b/Cloud_Manager/Services/ProductRepo.cs new file mode 100644 index 0000000..52161a8 --- /dev/null +++ b/Cloud_Manager/Services/ProductRepo.cs @@ -0,0 +1,411 @@ +using Cloud_Manager; +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Data; +using System.Data.Common; +using System.Text.Json; + +namespace Cloud_Manager.Services +{ + public class ProductRepo : IProduct + { + private readonly BiskAcdbContext m_context; + private readonly ITokenService m_tokenService; + private readonly HttpContext m_httpContext; + + public event EventHandler ProductsChanged; + public event EventHandler UnitsChanged; + public event EventHandler BrandsChanged; + public event EventHandler CategoriesChanged; + + public ProductRepo(BiskAcdbContext a_context, ITokenService a_tokenService, IHttpContextAccessor a_httpContextAccessor) + { + m_context = a_context; + m_tokenService = a_tokenService; + m_httpContext = a_httpContextAccessor?.HttpContext; + } + /// + /// Gets all products from the server + /// + /// + public IEnumerable GetProducts(string a_productKey = "") + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetProducts(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", string.Join(", ", accessiblebranches.ToArray()))); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + List pUnits = new List(); + + yield return new ProductItem + { + Product = new Tblproduct + { + Pcode = reader.GetString(0), + ProductName = reader.GetString(1), + Pdesc = reader.GetString(2), + BaseUnit = reader.GetString(3), + Costprice = reader.GetDecimal(4), + Status = reader.GetString(5), + Price = reader.GetDecimal(6), + BranchId = reader.GetString(7), + }, + BaseUnit = reader.GetString(3), + Stock = new Tblinventory + { + Quantity = reader.GetInt32(8) + }, + Restocklevel = new Restocklevel + { + WarnLevel = reader.GetInt32(9), + Unit = reader.GetString(10), + }, + Units = GetAltUnits(reader) + }; + } + } + } + } + } + private List GetAltUnits(DbDataReader a_reader) + { + List pUnits = new List(); + for (int i = 1; i < 5; i++) + { + if (!a_reader.IsDBNull(a_reader.GetOrdinal($"AltUnit{i}"))) + { + pUnits.Add(new ProductUnits + { + UnitCode = a_reader.GetFieldValue($"AltUnit{i}"), + QuantityUnit = a_reader.GetFieldValue($"AltUnit{i}QTY"), + PriceUnit = a_reader.GetFieldValue($"AltUnit{i}Price"), + DistinctiveCode = a_reader.GetFieldValue($"AltUnit{i}distinctiveCode") + }); + } + else + { + return pUnits; + } + } + return pUnits; + } + + public IEnumerable GetUnitofmeasures() + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + return m_context.Unitofmeasures.Where(b => accessiblebranches.Contains(b.BranchId)); + } + return new List(); + } + + + + public IEnumerable GetBrands(string a_brandKey = "") + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + return m_context.Tblbrands.Where(b => accessiblebranches.Contains(b.BranchId)); + } + return new List(); + } + + public IEnumerable GetCategories(string a_categoryKey = "") + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + return m_context.Tblcategories.Where(b => accessiblebranches.Contains(b.BranchId)); + } + return new List(); + } + public async Task SyncProducts(List a_item) + { + try + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL ProductSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + + public async Task SyncInventory(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InventorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncInventoryEntries(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InventoryEntriesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncPriceChanges(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL PriceChangeSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncProductAltUnit(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL ProductAltUnitSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncRestockAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL RestockLevelsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncUnitOfMeasureAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL UnitOfMeasureSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncStockAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL StockSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncBrandsAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL BrandSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCategoriesAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CategorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000, 01, 01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } + #region Only Need to implement in the client Side + public Task FetchUnits() + { + throw new NotImplementedException(); + } + public Task FetchProducts() + { + throw new NotImplementedException(); + } + + public ProductItem GetProductById(string a_id) + { + throw new NotImplementedException(); + } + + public ProductItem GetProductByName(string name) + { + throw new NotImplementedException(); + } + + public void RefreshList() + { + throw new NotImplementedException(); + } + + public string GetUnitName(string a_unitCode) + { + throw new NotImplementedException(); + } + public Task FetchBrands() + { + throw new NotImplementedException(); + } + + public Task FetchCategories() + { + throw new NotImplementedException(); + } + + public IEnumerable GetLowstockItems() + { + throw new NotImplementedException(); + } + + public Task FetchLowStockProducts() + { + throw new NotImplementedException(); + } + } + #endregion +} diff --git a/Cloud_Manager/Services/SalesService.cs b/Cloud_Manager/Services/SalesService.cs new file mode 100644 index 0000000..922caf2 --- /dev/null +++ b/Cloud_Manager/Services/SalesService.cs @@ -0,0 +1,381 @@ +using Cloud_Manager.CloudHubs; +using Cloud_Manager.Models.CustomModels; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.AspNetCore.SignalR; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Text.Json; + +namespace Cloud_Manager.Services +{ + public class SalesService : ISalesInterface + { + private readonly BiskAcdbContext m_context; + private readonly ITokenService m_tokenService; + private readonly HttpContext m_httpContext; + private readonly IHubContext m_salesHub; + + public event EventHandler TransactionsChanged; + public event EventHandler FetchComplete; + public event EventHandler FetchStart; + + public SalesService(BiskAcdbContext a_context, ITokenService a_tokenService, + IHttpContextAccessor a_httpContextAccessor, IHubContext a_salesHub) + { + m_context = a_context; + m_tokenService = a_tokenService; + m_httpContext = a_httpContextAccessor?.HttpContext; + m_salesHub = a_salesHub; + } + + public Task FetchRecentTransaction(int a_limit) + { + throw new NotImplementedException(); + } + + public IEnumerable GetRecentTransaction() + { + throw new NotImplementedException(); + } + + public IEnumerable GetTransactions(DateTime a_start, DateTime a_end) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetTransactionsByDate(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_start.ToString("yyyy-MM-dd"))); + command.Parameters.Add(new MySqlParameter("@p1", a_end.ToString("yyyy-MM-dd"))); + command.Parameters.Add(new MySqlParameter("@p2", string.Join(", ", accessiblebranches.ToArray()))); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + yield return new SaleItem + { + Transno = reader.GetString(0), + Total = (decimal)reader.GetDouble(1), + Date = reader.GetDateTime(2), + Cashier = reader.GetString(3), + BranchId = reader.GetString(4), + Customer = reader.GetString(5), + Status = reader.GetString(6), + }; + } + } + } + } + } + + public Task FetchTransaction(DateTime a_start, DateTime a_end) + { + throw new NotImplementedException(); + } + + public Task FetchReceipt(string a_receiptId) + { + throw new NotImplementedException(); + } + + public IEnumerable GetReceipt(string a_receiptId) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetTransactionsById(@p0,@p1)"; + command.Parameters.Add(new MySqlParameter("@p0", a_receiptId)); + command.Parameters.Add(new MySqlParameter("@p1", string.Join(", ", accessiblebranches.ToArray()))); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + yield return new SaleItem + { + Transno = reader.GetString(0), + Total = (decimal)reader.GetDouble(1), + Date = reader.GetDateTime(2), + Cashier = reader.GetString(3), + BranchId = reader.GetString(4), + Customer = reader.GetString(5), + Status = reader.GetString(6), + }; + } + } + // Close the connection explicitly + m_context.Database.CloseConnection(); + } + } + } + + public Task> GetReceiptDetail(string a_receiptId) + { + List details = new List(); + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "CALL GetReceiptDetails(@p0,@p1)"; + command.Parameters.Add(new MySqlParameter("@p0", a_receiptId)); + command.Parameters.Add(new MySqlParameter("@p1", string.Join(", ", accessiblebranches.ToArray()))); + + m_context.Database.OpenConnection(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + details.Add(new Tblcart + { + Transno = a_receiptId, + Id = reader.GetString(0), + Quantity = reader.GetInt32(1), + Date = reader.GetDateTime(2), + Price = reader.GetDecimal(3), + Cashier = reader.GetString(4), + Status = reader.GetString(5), + Total = (decimal)reader.GetDouble(6), + Unit = reader.GetString(7), + Costprice = reader.GetDecimal(8), + BranchId = reader.GetString(9), + CountId = reader.GetString(10), + Tendered = reader.GetDecimal(11), + Balance = reader.GetDecimal(12), + ValueAddTax = reader.GetDecimal(13) + }); + } + } + } + } + return Task.FromResult(details.AsEnumerable()); + } + + public async Task SyncCart(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SaleSyncUpstream(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000, 01, 01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } + + public async Task SyncCancelledTransaction(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CancelledSaleSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCreditPurchase(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CreditPurchaseSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCustomerAccount(List a_customerAccounts) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_customerAccounts); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerAccountSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCustomerPurchase(List a_customerPurchase) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_customerPurchase); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerPurchasesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDiscountLogs(List a_discountLog) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_discountLog); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DiscountLogsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryDetailsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryHead(List a_heads) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_heads); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryheadSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryRecipients(List a_recipients) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_recipients); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryRecipientSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncInvoice(List a_invoice) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_invoice); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InvoiceSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + } +} diff --git a/Cloud_Manager/Services/UserService.cs b/Cloud_Manager/Services/UserService.cs new file mode 100644 index 0000000..b120fe3 --- /dev/null +++ b/Cloud_Manager/Services/UserService.cs @@ -0,0 +1,59 @@ +using Cloud_Manager; +using Cloud_Manager.Models.Enums; +using Cloud_Manager.Models.Interfaces; +using Cloud_Manager.Models.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Text.Json; + +namespace Cloud_Manager.Services +{ + public class UserService : IUser + { + private readonly BiskAcdbContext m_context; + private readonly ITokenService m_tokenService; + private readonly HttpContext m_httpContext; + + public UserService(BiskAcdbContext a_context, ITokenService a_tokenService, IHttpContextAccessor a_httpContextAccessor) + { + m_context = a_context; + m_tokenService = a_tokenService; + m_httpContext = a_httpContextAccessor?.HttpContext; + } + public IEnumerable FetchUsers() + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + IEnumerable accessiblebranches = m_tokenService.BranchIds(token); + + return m_context.Tblusers.Where(b => accessiblebranches.Contains(b.BranchId)); + } + return new List(); + } + + public Task> GetUsers() + { + throw new NotImplementedException(); + } + + public async Task SyncUserAsync(List a_users) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_users); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL UsersSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + } +} diff --git a/Cloud_Manager/WeatherForecast.cs b/Cloud_Manager/WeatherForecast.cs new file mode 100644 index 0000000..5f7c72a --- /dev/null +++ b/Cloud_Manager/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Cloud_Manager +{ + 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; } + } +} \ No newline at end of file diff --git a/Cloud_Manager/appsettings.Development.json b/Cloud_Manager/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Cloud_Manager/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Cloud_Manager/appsettings.json b/Cloud_Manager/appsettings.json new file mode 100644 index 0000000..2adec7e --- /dev/null +++ b/Cloud_Manager/appsettings.json @@ -0,0 +1,18 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "Connection": "server=54.37.19.162;database=dev_biskilogclients;user=biskilog;password=mefbuk-6niFsu-fytrew;AllowZeroDateTime=True;", + "PrivateConnection": "server={0};database={1};user=biskilog;password=mefbuk-6niFsu-fytrew;default command timeout=0;AllowZeroDateTime=True;" + }, + "AllowedHosts": "*", + "JWT": { + "Key": "@@BISKILOGACCOUNTING2023DEV??//##$", + "Issuer": "AUTH SERVER", + "Audience": "BISKILOG" + } +}