83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
using BusinessLogic.BusinessLogic;
|
|
using Contracts.BusinessLogicContracts;
|
|
using Contracts.SearchModels;
|
|
using Contracts.ViewModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Reflection;
|
|
using WebApp.Helpers;
|
|
|
|
namespace WebApp.Pages.User
|
|
{
|
|
[Authorize(Roles = Roles.User)]
|
|
public class PurchasesModel : PageModel
|
|
{
|
|
public List<PurchaseViewModel> purchaseViewModels { get; set; }
|
|
public UserViewModel userViewModel { get; set; }
|
|
public BillViewModel billViewModel { get; set; }
|
|
[BindProperty]
|
|
public PurchaseSearchModel purchaseSearchModel { get; set; }
|
|
public void OnGet(DateTime? datefrom, DateTime? dateto)
|
|
{
|
|
var UserId = this.GetUserId();
|
|
if (UserId is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
userViewModel = APIClient.GetRequest<UserViewModel>($"user/get?id={UserId}");
|
|
|
|
string request = "Purchase/GetList";
|
|
|
|
request += $"?userid={UserId}&";
|
|
|
|
if (datefrom != null)
|
|
request += $"?datefrom={datefrom}&";
|
|
|
|
if (dateto != null)
|
|
request += $"?datefrom={dateto}&";
|
|
|
|
purchaseViewModels = APIClient.GetRequest<List<PurchaseViewModel>>(request);
|
|
}
|
|
|
|
public void OnPostSendBill(Guid id)
|
|
{
|
|
var UserId = this.GetUserId();
|
|
if (UserId is null)
|
|
{
|
|
OnGet(null, null);
|
|
}
|
|
userViewModel = APIClient.GetRequest<UserViewModel>($"user/get?id={UserId}");
|
|
|
|
var purchase = APIClient.GetRequest<PurchaseViewModel>($"purchase/get?id={id}");
|
|
var products = APIClient.GetRequest<List<ProductViewModel>>($"purchase/getproducts?purchaseid={id}");
|
|
|
|
billViewModel = new BillViewModel();
|
|
billViewModel.UserId = new Guid(this.GetUserId());
|
|
billViewModel.PurchaseId = id;
|
|
billViewModel.Products = products;
|
|
billViewModel.Count = purchase.ProductCount;
|
|
billViewModel.Cost = purchase.Cost;
|
|
billViewModel.DateCreated = purchase.DateCreated;
|
|
billViewModel.UserFirstName = userViewModel.FirstName;
|
|
billViewModel.UserLastName = userViewModel.SecondName;
|
|
billViewModel.UserEmail = userViewModel.Email;
|
|
|
|
APIClient.PostRequest($"purchase/createbill", billViewModel);
|
|
|
|
OnGet(null, null);
|
|
}
|
|
public byte[] GetStatistics()
|
|
{
|
|
var UserId = this.GetUserId();
|
|
if (UserId is null)
|
|
{
|
|
OnGet(null, null);
|
|
}
|
|
var chart = APIClient.GetRequest<byte[]>($"purchase/createchart?userId={UserId}");
|
|
return chart;
|
|
}
|
|
}
|
|
}
|