yavsc/Yavsc/Controllers/FrontOfficeController.cs

135 lines
4.7 KiB
C#
Raw Normal View History

2016-05-17 18:22:18 +02:00
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Logging;
2016-08-01 01:43:15 +02:00
using System;
2017-02-03 15:24:59 +01:00
using System.Linq;
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;
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;
2018-03-26 19:27:29 +02:00
using Yavsc.Abstract.FileSystem;
using Yavsc.Services;
2017-02-27 19:28:32 +01:00
2016-05-17 18:22:18 +02:00
public class FrontOfficeController : Controller
{
ApplicationDbContext _context;
UserManager<ApplicationUser> _userManager;
ILogger _logger;
2017-02-28 14:01:24 +01:00
IStringLocalizer _SR;
2016-05-17 18:22:18 +02:00
public FrontOfficeController(ApplicationDbContext context,
UserManager<ApplicationUser> userManager,
2017-02-28 14:01:24 +01:00
ILoggerFactory loggerFactory,
IStringLocalizer<Yavsc.Resources.YavscLocalisation> 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;
2016-05-17 18:22:18 +02:00
}
public ActionResult Index()
{
var uid = User.GetUserId();
var now = DateTime.Now;
2017-02-03 15:24:59 +01:00
var model = new FrontOfficeIndexViewModel
{
2017-06-08 00:26:29 +02:00
EstimateToProduceCount = _context.RdvQueries.Where(c => c.PerformerId == uid && c.EventDate > now
2017-02-03 15:24:59 +01:00
&& c.ValidationDate == null && !_context.Estimates.Any(e => (e.CommandId == c.Id && e.ProviderValidationDate != null))).Count(),
2017-06-08 00:26:29 +02:00
EstimateToSignAsProCount = _context.RdvQueries.Where(c => (c.PerformerId == uid && c.EventDate > now
2017-02-03 15:24:59 +01:00
&& c.ValidationDate == null && _context.Estimates.Any(e => (e.CommandId == c.Id && e.ProviderValidationDate != null)))).Count(),
EstimateToSignAsCliCount = _context.Estimates.Where(e => e.ClientId == uid && e.ClientValidationDate == null).Count(),
BillToSignAsProCount = 0,
BillToSignAsCliCount = 0,
NewPayementsCount = 0
};
return View(model);
2016-05-17 18:22:18 +02:00
}
2017-02-27 19:28:32 +01:00
[AllowAnonymous]
2017-02-12 23:53:53 +01:00
public 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");
}
2017-02-03 15:24:59 +01:00
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(id);
return View(result);
2016-05-17 18:22:18 +02:00
}
2017-02-27 19:28:32 +01:00
[AllowAnonymous]
public ActionResult HairCut(string id)
2016-05-17 18:22:18 +02:00
{
2017-03-01 10:11:20 +01:00
if (id == null)
{
throw new NotImplementedException("No Activity code");
2016-05-17 18:22:18 +02:00
}
2017-03-01 10:11:20 +01:00
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(id);
2017-02-27 19:28:32 +01:00
return View(result);
2016-05-17 18:22:18 +02:00
}
2017-03-01 10:11:20 +01:00
2016-05-17 18:22:18 +02:00
2017-02-27 19:28:32 +01:00
2016-11-06 02:03:36 +01:00
[Produces("text/x-tex"), Authorize, Route("estimate-{id}.tex")]
public ViewResult EstimateTex(long id)
2016-05-17 18:22:18 +02:00
{
2016-11-07 19:34:56 +01:00
var estimate = _context.Estimates.Include(x => x.Query)
.Include(x => x.Query.Client)
.Include(x => x.Query.PerformerProfile)
.Include(x => x.Query.PerformerProfile.OrganizationAddress)
.Include(x => x.Query.PerformerProfile.Performer)
.Include(e => e.Bill).FirstOrDefault(x => x.Id == id);
2016-11-03 17:34:19 +01:00
Response.ContentType = "text/x-tex";
return View("Estimate.tex", estimate);
2016-05-17 18:22:18 +02:00
}
2016-11-07 19:34:56 +01:00
2017-02-03 15:24:59 +01:00
[Authorize, Route("Estimate-{id}.pdf")]
2016-11-09 14:03:57 +01:00
public IActionResult EstimatePdf(long id)
2016-11-06 02:03:36 +01:00
{
2016-11-07 19:34:56 +01:00
ViewBag.TempDir = Startup.SiteSetup.TempDir;
2018-03-26 19:27:29 +02:00
ViewBag.BillsDir = AbstractFileSystemHelpers.UserBillsDirName;
2016-11-07 19:34:56 +01:00
var estimate = _context.Estimates.Include(x => x.Query)
.Include(x => x.Query.Client)
.Include(x => x.Query.PerformerProfile)
.Include(x => x.Query.PerformerProfile.OrganizationAddress)
.Include(x => x.Query.PerformerProfile.Performer)
2017-02-03 15:24:59 +01:00
.Include(e => e.Bill).FirstOrDefault(x => x.Id == id);
if (estimate == null)
2016-11-07 19:34:56 +01:00
throw new Exception("No data");
2017-02-03 15:24:59 +01:00
return View("Estimate.pdf", estimate);
2016-11-06 02:03:36 +01:00
}
2017-01-16 15:34:05 +01:00
[Authorize]
public IActionResult EstimateProValidation()
{
throw new NotImplementedException();
}
[Authorize]
public IActionResult EstimateClientValidation()
{
throw new NotImplementedException();
2017-02-03 15:24:59 +01:00
2017-01-16 15:34:05 +01:00
}
[Authorize]
public IActionResult BillValidation()
{
throw new NotImplementedException();
2017-02-03 15:24:59 +01:00
2017-01-16 15:34:05 +01:00
}
[Authorize]
public IActionResult BillAcquitment()
{
throw new NotImplementedException();
}
2017-02-03 15:24:59 +01:00
}
2016-11-09 14:03:57 +01:00
}