Added admin endpoints

Added inventory and sales api endpoints
This commit is contained in:
s459315 2022-08-02 19:32:39 +02:00
parent 43f647d9b7
commit f118635029
12 changed files with 148 additions and 0 deletions

View File

@ -77,6 +77,9 @@
<Build Include="dbo\Stored Procedures\spSaleInsert.sql" />
<Build Include="dbo\Stored Procedures\spSaleDetailInsert.sql" />
<Build Include="dbo\Stored Procedures\spSaleLookUp.sql" />
<Build Include="dbo\Stored Procedures\spInventoryGetAll.sql" />
<Build Include="dbo\Stored Procedures\spInventoryInsert.sql" />
<Build Include="dbo\Stored Procedures\spSaleSaleReport.sql" />
</ItemGroup>
<ItemGroup>
<RefactorLog Include="RMData.refactorlog" />

View File

@ -0,0 +1,9 @@
CREATE PROCEDURE [dbo].[spInventoryGetAll]
AS
BEGIN
SET NOCOUNT ON;
SELECT [Id], [ProductId], [Quantity], [PurchasePrice], [PurchaseDate]
from dbo.Inventory;
END

View File

@ -0,0 +1,14 @@
CREATE PROCEDURE [dbo].[spInventoryInsert]
-- [ProductId], [Quantity], [PurchasePrice], [PurchaseDate]
@ProductId int,
@Quantity int,
@PurchasePrice money,
@PurchaseDate datetime2
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.Inventory (ProductId, Quantity, PurchasePrice, PurchaseDate)
VALUES (@ProductId, @Quantity, @PurchasePrice, @PurchaseDate);
END

View File

@ -0,0 +1,10 @@
CREATE PROCEDURE [dbo].[spSaleSaleReport]
AS
BEGIN
SET NOCOUNT ON;
SELECT [S].[SaleDate], [S].[SubTotal], [S].[Tax], [S].[Total], [U].FirstName, [U].LastName, [U].EmailAddress
FROM dbo.Sale AS S
INNER JOIN dbo.[User] AS U
ON S.CashierId = U.Id
END

View File

@ -0,0 +1,27 @@
using RMDataManagerLibrary.DataAcccess;
using RMDataManagerLibrary.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace RMDataManager.Controllers
{
[Authorize]
public class InventoryController : ApiController
{
public List<InventoryModel> Get()
{
InventoryData data = new InventoryData();
return data.GetInventory();
}
public void Post(InventoryModel item)
{
InventoryData data = new InventoryData();
data.SaveInventoryRecord(item);
}
}
}

View File

@ -20,5 +20,13 @@ namespace RMDataManager.Controllers
data.SaveSale(sale, cashierId);
}
[Route("GetSalesReport")]
public List<SaleReportModel> GetSalesReport()
{
SaleData data = new SaleData();
return data.GetSaleReport();
}
}
}

View File

@ -213,6 +213,7 @@
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\InventoryController.cs" />
<Compile Include="Controllers\ProductController.cs" />
<Compile Include="Controllers\SaleController.cs" />
<Compile Include="Controllers\UserController.cs" />

View File

@ -0,0 +1,29 @@
using RMDataManagerLibrary.Internal.DataAccess;
using RMDataManagerLibrary.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.DataAcccess
{
public class InventoryData
{
public List<InventoryModel> GetInventory()
{
SqlDataAccess sql = new SqlDataAccess();
var output = sql.LoadData<InventoryModel, dynamic>("dbo.spInventoryGetAll", new { }, "RMData");
return output;
}
public void SaveInventoryRecord(InventoryModel item)
{
SqlDataAccess sql = new SqlDataAccess();
sql.SaveData("dbo.spInventoryInsert", item, "RMData");
}
}
}

View File

@ -80,6 +80,15 @@ namespace RMDataManagerLibrary.DataAcccess
}
}
}
public List<SaleReportModel> GetSaleReport()
{
SqlDataAccess sql = new SqlDataAccess();
var output = sql.LoadData<SaleReportModel, dynamic>("dbo.spSaleSaleReport", new { }, "RMData");
return output;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.Models
{
public class InventoryModel
{
public int ProductId { get; set; }
public int Quantity { get; set; }
public decimal PurchasePrice { get; set; }
public DateTime PurchaseDate { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.Models
{
public class SaleReportModel
{
public DateTime SaleDate { get; set; }
public decimal SubTotal { get; set; }
public decimal Tax { get; set; }
public decimal Total { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
}
}

View File

@ -46,14 +46,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigHelper.cs" />
<Compile Include="DataAcccess\InventoryData.cs" />
<Compile Include="DataAcccess\ProductData.cs" />
<Compile Include="DataAcccess\SaleData.cs" />
<Compile Include="DataAcccess\UserData.cs" />
<Compile Include="Models\InventoryModel.cs" />
<Compile Include="Models\ProductModel.cs" />
<Compile Include="Models\SaleDBModel.cs" />
<Compile Include="Models\SaleDetailDBModel.cs" />
<Compile Include="Models\SaleDetailModel.cs" />
<Compile Include="Models\SaleModel.cs" />
<Compile Include="Models\SaleReportModel.cs" />
<Compile Include="Models\UserModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Internal\DataAccess\SqlDataAccess.cs" />