196 lines
5.3 KiB
C#
196 lines
5.3 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.RollCall;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using CompanyManagment.App.Contracts.YearlySalary;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Security.Claims;
|
|
|
|
namespace ServiceHost.Areas.Client.Pages.Company.Checkouts
|
|
{
|
|
[Authorize]
|
|
public class IndexModel : PageModel
|
|
{
|
|
#region Entities
|
|
|
|
public List<CheckoutViewModel> Checkouts;
|
|
public CheckoutSearchModel SearchModel;
|
|
public List<EmployeeSelectListViewModel> Employees;
|
|
public string Year;
|
|
public string Month;
|
|
public long EmployeeId;
|
|
public string ContarctStart;
|
|
public string ContarctEnd;
|
|
public long WorkshopId;
|
|
public string Sorting;
|
|
public string WorkshopName { get; set; }
|
|
public List<string> YearlyList;
|
|
private readonly ICheckoutApplication _checkoutApplication;
|
|
private readonly IWorkshopApplication _workshopApplication;
|
|
private readonly IYearlySalaryApplication _yearlySalaryApplication;
|
|
private readonly IPasswordHasher _passwordHasher;
|
|
private readonly IRollCallApplication rollCallApplication;
|
|
public int PageIndex;
|
|
|
|
|
|
#endregion
|
|
|
|
public IndexModel(IWorkshopApplication workshopApplication,
|
|
IEmployeeApplication employeeApplication,
|
|
IYearlySalaryApplication yearlySalaryApplication,
|
|
ICheckoutApplication checkoutApplication, IPasswordHasher passwordHasher, IRollCallApplication rollCallApplication)
|
|
{
|
|
|
|
_workshopApplication = workshopApplication;
|
|
|
|
_yearlySalaryApplication = yearlySalaryApplication;
|
|
|
|
|
|
_checkoutApplication = checkoutApplication;
|
|
_passwordHasher = passwordHasher;
|
|
this.rollCallApplication = rollCallApplication;
|
|
}
|
|
|
|
#region FirstLoad-OnGet
|
|
|
|
public IActionResult OnGet(CheckoutSearchModel searchModel)
|
|
{
|
|
var workshopHash = User.FindFirstValue("WorkshopSlug");
|
|
var workshopId = _passwordHasher.SlugDecrypt(workshopHash);
|
|
if (workshopId > 0)
|
|
{
|
|
searchModel.Sorting = string.IsNullOrWhiteSpace(searchModel.Sorting)
|
|
? "CreationDate-Max"
|
|
: searchModel.Sorting;
|
|
searchModel.PageIndex = 0;
|
|
Year = searchModel.Year;
|
|
Month = searchModel.Month;
|
|
ContarctStart = searchModel.ContractStart;
|
|
ContarctEnd = searchModel.ContractEnd;
|
|
EmployeeId = searchModel.EmployeeId;
|
|
WorkshopId = workshopId == 0 ? searchModel.WorkshopId : workshopId;
|
|
searchModel.WorkshopId = WorkshopId;
|
|
Sorting = string.IsNullOrWhiteSpace(searchModel.Sorting) ? "CreationDate-Max" : searchModel.Sorting;
|
|
var workshopInfo = _workshopApplication.GetWorkshopInfo(WorkshopId);
|
|
WorkshopName = workshopInfo.WorkshopFullName;
|
|
Employees = workshopInfo.EmployeeList.Select(x => new EmployeeSelectListViewModel()
|
|
{ Id = x.Id, EmployeeFullName = x.EmployeeFullName }).ToList();
|
|
Checkouts = _checkoutApplication.SearchForClient(searchModel);
|
|
PageIndex = Checkouts.Count;
|
|
YearlyList =
|
|
_yearlySalaryApplication.GetYears();
|
|
SearchModel = new CheckoutSearchModel()
|
|
{
|
|
Year = string.IsNullOrWhiteSpace(searchModel.Year) ? " " : searchModel.Year,
|
|
Month = string.IsNullOrWhiteSpace(searchModel.Month) ? " " : searchModel.Month,
|
|
ContractStart = searchModel.ContractStart,
|
|
ContractEnd = searchModel.ContractEnd,
|
|
EmployeeId = searchModel.EmployeeId,
|
|
Sorting = searchModel.Sorting,
|
|
|
|
|
|
};
|
|
return Page();
|
|
}
|
|
else
|
|
{
|
|
return Redirect("error/401");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Pagination
|
|
|
|
public IActionResult OnGetPagination(int pageIndex, long workshopId, long employeeId, string year, string month, string start, string end, string sorting)
|
|
{
|
|
var searchModel = new CheckoutSearchModel()
|
|
{
|
|
PageIndex = pageIndex,
|
|
WorkshopId = workshopId,
|
|
EmployeeId = employeeId,
|
|
Year = year,
|
|
Month = month,
|
|
ContractStart = start,
|
|
ContractEnd = end,
|
|
Sorting = sorting
|
|
};
|
|
|
|
var search = _checkoutApplication.SearchForClient(searchModel);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
contractResultViewModels = search,
|
|
pageIndex = search.Count
|
|
|
|
});
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PrintOne
|
|
|
|
public IActionResult OnGetPrintOne(long id)
|
|
{
|
|
|
|
var res = _checkoutApplication.PrintOne(id);
|
|
if (res.HasRollCall)
|
|
return Partial("PrintOneRollCall", res);
|
|
|
|
return Partial("PrintOne", res);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PrintOneMobile
|
|
public IActionResult OnGetPrintOneMobile(long id)
|
|
{
|
|
|
|
var res = _checkoutApplication.PrintOne(id);
|
|
if (res.HasRollCall)
|
|
return Partial("PrintOneRollCall", res);
|
|
|
|
return Partial("PrintOneMobile", res);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region LoadAllToPrint
|
|
public IActionResult OnGetLoadAllToPrint(long workshopId, long employeeId, string year, string month)
|
|
{
|
|
var searchModel = new CheckoutSearchModel()
|
|
{
|
|
SearchAll = true,
|
|
WorkshopId = workshopId,
|
|
EmployeeId = employeeId,
|
|
Year = year,
|
|
Month = month,
|
|
|
|
};
|
|
|
|
var search = _checkoutApplication.SearchForClient(searchModel);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
contractResultViewModels = search,
|
|
pageIndex = search.Count
|
|
|
|
});
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
public class Person
|
|
{
|
|
public string FirstName { get; set; }
|
|
public string LastName { get; set; }
|
|
public int Age { get; set; }
|
|
}
|
|
}
|