yavsc/src/Yavsc.Org/Controllers/Contracting/FrontOfficeController.cs

81 lines
3.1 KiB
C#
Raw Normal View History

2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using System.Security.Claims;
2016-05-17 18:22:18 +02:00
namespace Yavsc.Controllers
{
2017-02-03 15:24:59 +01:00
using Helpers;
2023-03-19 17:57:55 +00:00
using Microsoft.EntityFrameworkCore;
2017-02-28 14:01:24 +01:00
using Microsoft.Extensions.Localization;
2017-02-03 15:24:59 +01:00
using Models;
using ViewModels.FrontOffice;
2025-02-17 23:56:28 +00:00
using Yavsc.Server.Helpers;
2018-03-26 19:27:29 +02:00
using Yavsc.Services;
2017-02-27 19:28:32 +01:00
2016-05-17 18:22:18 +02:00
public class FrontOfficeController : Controller
{
2020-10-09 19:35:39 +01:00
readonly ApplicationDbContext _context;
readonly UserManager<ApplicationUser> _userManager;
readonly ILogger _logger;
readonly IStringLocalizer _SR;
private readonly IBillingService _billing;
2018-06-15 15:44:21 +02:00
2016-05-17 18:22:18 +02:00
public FrontOfficeController(ApplicationDbContext context,
UserManager<ApplicationUser> userManager,
2018-06-15 15:44:21 +02:00
IBillingService billing,
2017-02-28 14:01:24 +01:00
ILoggerFactory loggerFactory,
IStringLocalizer<FrontOfficeController> SR)
2016-05-17 18:22:18 +02:00
{
_context = context;
_userManager = userManager;
_logger = loggerFactory.CreateLogger<FrontOfficeController>();
2017-02-28 14:01:24 +01:00
_SR = SR;
2018-06-15 15:44:21 +02:00
_billing = billing;
2016-05-17 18:22:18 +02:00
}
2016-05-17 18:22:18 +02:00
public ActionResult Index()
{
2023-03-19 17:57:55 +00:00
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
2026-07-06 00:47:35 +01:00
var now = DateTime.UtcNow;
2017-02-03 15:24:59 +01:00
var model = new FrontOfficeIndexViewModel
{
2026-07-06 00:47:35 +01:00
EstimateToProduceCount = _context.RdvQueries.Where(c => c.PerformerId == uid && c.EventDate > now && c.Status == QueryStatus.Inserted
&& c.ValidationDate == null && !_context.Estimates.Any(e => e.CommandId == c.Id)).Count(),
EstimateToHonorAsProCount = _context.RdvQueries.Where(c => c.PerformerId == uid && c.EventDate > now && (c.Status == QueryStatus.ProAccepted || c.Status == QueryStatus.Accepted)
2026-07-06 00:47:35 +01:00
&& c.ValidationDate == null && _context.Estimates.Any(e => e.CommandId == c.Id )).Count(),
EstimateToSignAsCliCount = _context.Estimates.Where(e => e.ClientId == uid && (e.Query.Status == QueryStatus.ProAccepted || e.Query.Status == QueryStatus.Accepted)).Count(),
2026-07-06 00:47:35 +01:00
BillToSignAsCliCount = 0,
NewPayementsCount = 0
};
return View(model);
2016-05-17 18:22:18 +02:00
}
2017-02-27 19:28:32 +01:00
[AllowAnonymous]
2025-02-24 23:29:48 +00:00
public async Task<ActionResult> Profiles(string id)
2016-05-17 18:22:18 +02:00
{
2016-11-07 19:34:56 +01:00
if (id == null)
{
2016-08-01 01:43:15 +02:00
throw new NotImplementedException("No Activity code");
}
2025-02-24 23:29:48 +00:00
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
var result = await _context.ListPerformersAsync(_billing, id);
return View(result);
2016-05-17 18:22:18 +02:00
}
2019-07-22 17:25:12 +02:00
2017-02-27 19:28:32 +01:00
[AllowAnonymous]
2026-07-04 22:25:59 +01:00
public async Task <ActionResult> ListPerformersAsync(string activityCode)
2016-05-17 18:22:18 +02:00
{
2026-07-04 22:25:59 +01:00
if (activityCode == null)
2017-03-01 10:11:20 +01:00
{
throw new NotImplementedException("No Activity code");
2016-05-17 18:22:18 +02:00
}
2026-07-04 22:25:59 +01:00
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == activityCode);
var result = await _context.ListPerformersAsync(_billing, activityCode);
2017-02-27 19:28:32 +01:00
return View(result);
2016-05-17 18:22:18 +02:00
}
2017-02-03 15:24:59 +01:00
}
2016-11-09 14:03:57 +01:00
}