yavsc/Yavsc/Controllers/FrontOfficeController.cs

148 lines
5.3 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;
using Models;
2017-02-11 15:46:26 +01:00
using Models.Workflow;
2017-02-03 15:24:59 +01:00
using ViewModels.FrontOffice;
2016-05-17 18:22:18 +02:00
public class FrontOfficeController : Controller
{
ApplicationDbContext _context;
UserManager<ApplicationUser> _userManager;
ILogger _logger;
public FrontOfficeController(ApplicationDbContext context,
UserManager<ApplicationUser> userManager,
ILoggerFactory loggerFactory)
{
_context = context;
_userManager = userManager;
_logger = loggerFactory.CreateLogger<FrontOfficeController>();
}
public ActionResult Index()
{
var uid = User.GetUserId();
var now = DateTime.Now;
2017-02-03 15:24:59 +01:00
var model = new FrontOfficeIndexViewModel
{
EstimateToProduceCount = _context.Commands.Where(c => c.PerformerId == uid && c.EventDate > now
&& c.ValidationDate == null && !_context.Estimates.Any(e => (e.CommandId == c.Id && e.ProviderValidationDate != null))).Count(),
EstimateToSignAsProCount = _context.Commands.Where(c => (c.PerformerId == uid && c.EventDate > now
&& 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-12 23:53:53 +01:00
[Route("Profiles/{id?}"), HttpGet, AllowAnonymous]
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-13 01:32:03 +01:00
[Route("Profiles/{id}"), HttpPost, AllowAnonymous]
public ActionResult Profiles(BookQuery bookQuery)
2016-05-17 18:22:18 +02:00
{
2016-11-07 19:34:56 +01:00
if (ModelState.IsValid)
{
2016-05-17 18:22:18 +02:00
var pro = _context.Performers.Include(
pr => pr.Performer
).FirstOrDefault(
2016-11-07 19:34:56 +01:00
x => x.PerformerId == bookQuery.PerformerId
2016-05-17 18:22:18 +02:00
);
2016-11-07 19:34:56 +01:00
if (pro == null)
2016-05-17 18:22:18 +02:00
return HttpNotFound();
// Let's create a command
2016-11-07 19:34:56 +01:00
if (bookQuery.Id == 0)
2016-05-17 18:22:18 +02:00
{
_context.BookQueries.Add(bookQuery);
}
2016-11-07 19:34:56 +01:00
else
{
2016-05-17 18:22:18 +02:00
_context.BookQueries.Update(bookQuery);
}
2017-02-23 03:10:30 +01:00
_context.SaveChanges(User.GetUserId());
2016-05-17 18:22:18 +02:00
// TODO Send sys notifications &
// notify the user (make him a basket badge)
return View("Index");
}
ViewBag.Activities = _context.ActivityItems(null);
2017-02-13 01:32:03 +01:00
return View("Profiles", _context.Performers.Include(p => p.Performer).Where
2016-05-17 18:22:18 +02:00
(p => p.Active).OrderBy(
2016-11-07 19:34:56 +01:00
x => x.MinDailyCost
2016-05-17 18:22:18 +02: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;
ViewBag.BillsDir = Startup.UserBillsDirName;
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
}