Benjamin Arhen
2 years ago
31 changed files with 19174 additions and 159 deletions
@ -0,0 +1,38 @@ |
|||
@page "/customers" |
|||
@using Biskilog_Accounting.Shared.CustomModels; |
|||
@using Biskilog_Accounting.Shared.Interfaces; |
|||
@using Biskilog_Accounting.Client.Pages.Transactions.Elements; |
|||
@using BlazorDateRangePicker; |
|||
@inject ICalculator m_calculator |
|||
@inject ContextMenuService ContextMenuService |
|||
@inject DialogService m_dialogService |
|||
@inject ISearchService m_searchControl |
|||
@implements IDisposable |
|||
@inject IMainInterface m_mainInterface |
|||
@inject ICustomer m_customerService |
|||
<h3>Customers</h3> |
|||
<RadzenDataGrid AllowPaging="true" PageSize="50" AllowSorting="true" Data="@m_customers" TItem="CustomerAccounts" |
|||
GridLines="DataGridGridLines.Horizontal"> |
|||
<Columns> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.Firstname" Title="Name"> |
|||
<Template Context="detail"> |
|||
@(detail.Customer.Firstname + " ") @(detail.Customer.Surname) |
|||
</Template> |
|||
</RadzenDataGridColumn> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.Telephone" Title="Telephone" /> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.Address" Title="Address" /> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.DateAdded" Title="Date Added" /> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.Status" Title="Status" Width="10%" /> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.Debt" Title="Balance"> |
|||
<Template Context="detail"> |
|||
@( |
|||
m_calculator.FormatMoneyWithCurrency((double)detail.Debt) |
|||
) |
|||
</Template> |
|||
</RadzenDataGridColumn> |
|||
<RadzenDataGridColumn TItem="CustomerAccounts" Property="Customer.BranchId" Title="Branch" Resizable Reorderable /> |
|||
</Columns> |
|||
</RadzenDataGrid> |
|||
@code { |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
using Biskilog_Accounting.Client.Pages.Users; |
|||
using Biskilog_Accounting.Shared.CustomModels; |
|||
|
|||
namespace Biskilog_Accounting.Client.Pages.Customers |
|||
{ |
|||
public partial class Customers |
|||
{ |
|||
private IEnumerable<CustomerAccounts> m_customers { get; set; } = Enumerable.Empty<CustomerAccounts>(); |
|||
protected override void OnInitialized() |
|||
{ |
|||
m_customers = m_customerService.FetchCustomers(); |
|||
base.OnInitialized(); |
|||
} |
|||
public void Dispose() |
|||
{ } |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
@page "/users" |
|||
@using Biskilog_Accounting.Shared.Interfaces; |
|||
@using Biskilog_Accounting.Shared.POSModels; |
|||
@inject IUser m_userService; |
|||
<h3>Users</h3> |
|||
<RadzenDataGrid AllowPaging="true" PageSize="50" AllowSorting="true" Data="@m_users" TItem="Tbluser" |
|||
GridLines="DataGridGridLines.Horizontal"> |
|||
<Columns> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="Username" Title="Username" /> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="Firstname" Title="Name"> |
|||
<Template Context="detail"> |
|||
@(detail.Firstname + "") @(detail.Surname) |
|||
</Template> |
|||
</RadzenDataGridColumn> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="StreetAddress1" Title="Address" /> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="AccessLevel" Title="Level" /> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="LastLogin" Title="Last Login" /> |
|||
<RadzenDataGridColumn TItem="Tbluser" Property="BranchId" Title="Branch" Resizable Reorderable /> |
|||
</Columns> |
|||
</RadzenDataGrid> |
|||
@code { |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
|
|||
namespace Biskilog_Accounting.Client.Pages.Users |
|||
{ |
|||
public partial class Users |
|||
{ |
|||
private IEnumerable<Tbluser> m_users { get; set; } = Enumerable.Empty<Tbluser>(); |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
m_users = m_userService.FetchUsers(); |
|||
base.OnInitialized(); |
|||
} |
|||
public void Dispose() |
|||
{ } |
|||
} |
|||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@ |
|||
using Biskilog_Accounting.Shared.CustomModels; |
|||
using Biskilog_Accounting.Shared.Interfaces; |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace Biskilog_Accounting.Server.Controllers |
|||
{ |
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class CustomerController : ControllerBase |
|||
{ |
|||
private readonly ICustomer m_customerService; |
|||
public CustomerController(ICustomer a_customerService) |
|||
{ |
|||
m_customerService = a_customerService; |
|||
} |
|||
/// <summary>
|
|||
/// Endpoint to return all customers
|
|||
/// </summary>
|
|||
[Authorize] |
|||
[HttpGet, Route("accounts")] |
|||
public IEnumerable<CustomerAccounts> GetCustomers() |
|||
{ |
|||
return m_customerService.FetchCustomers(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using Biskilog_Accounting.Shared.Interfaces; |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace Biskilog_Accounting.Server.Controllers |
|||
{ |
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class UsersController : ControllerBase |
|||
{ |
|||
private readonly IUser m_userService; |
|||
public UsersController(IUser a_userService) |
|||
{ |
|||
m_userService = a_userService; |
|||
} |
|||
/// <summary>
|
|||
/// Endpoint to return all users
|
|||
/// </summary>
|
|||
[Authorize] |
|||
[HttpGet, Route("accounts")] |
|||
public IEnumerable<Tbluser> GetUsers() |
|||
{ |
|||
return m_userService.FetchUsers(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,71 @@ |
|||
using Biskilog_Accounting.Server.POSModels; |
|||
using Biskilog_Accounting.Shared.CustomModels; |
|||
using Biskilog_Accounting.Shared.Enums; |
|||
using Biskilog_Accounting.Shared.Interfaces; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Net.Http.Headers; |
|||
using MySqlConnector; |
|||
using System.Drawing.Drawing2D; |
|||
|
|||
namespace Biskilog_Accounting.Server.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<CustomerAccounts> FetchCustomers() |
|||
{ |
|||
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|||
|
|||
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|||
{ |
|||
IEnumerable<string> 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 Shared.POSModels.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<IEnumerable<CustomerAccounts>> GetCustomers() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
using Biskilog_Accounting.Server.POSModels; |
|||
using Biskilog_Accounting.Shared.CustomModels; |
|||
using Biskilog_Accounting.Shared.Enums; |
|||
using Biskilog_Accounting.Shared.Interfaces; |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Net.Http.Headers; |
|||
using MySqlConnector; |
|||
using System.Drawing.Drawing2D; |
|||
|
|||
namespace Biskilog_Accounting.Server.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<Tbluser> FetchUsers() |
|||
{ |
|||
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|||
|
|||
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|||
{ |
|||
IEnumerable<string> accessiblebranches = m_tokenService.BranchIds(token); |
|||
|
|||
return m_context.Tblusers.Where(b => accessiblebranches.Contains(b.BranchId)); |
|||
} |
|||
return new List<Tbluser>(); |
|||
} |
|||
|
|||
public Task<IEnumerable<Tbluser>> GetUsers() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
using Biskilog_Accounting.Shared.CustomModels; |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
|
|||
namespace Biskilog_Accounting.Shared.Interfaces |
|||
{ |
|||
public interface ICustomer |
|||
{ |
|||
IEnumerable<CustomerAccounts> FetchCustomers(); |
|||
Task<IEnumerable<CustomerAccounts>> GetCustomers(); |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
using Biskilog_Accounting.Shared.POSModels; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Biskilog_Accounting.Shared.Interfaces |
|||
{ |
|||
public interface IUser |
|||
{ |
|||
IEnumerable<Tbluser> FetchUsers(); |
|||
Task<IEnumerable<Tbluser>> GetUsers(); |
|||
} |
|||
} |
Loading…
Reference in new issue