yavsc/Yavsc/Controllers/FrontOfficeController.cs

120 lines
4.2 KiB
C#
Raw Normal View History

2016-05-17 18:22:18 +02:00
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Authorization;
using Yavsc.Models;
using System.Linq;
using Microsoft.AspNet.Identity;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Logging;
using Yavsc.Models.Booking;
2016-06-12 01:32:51 +02:00
using Yavsc.Helpers;
2016-08-01 01:43:15 +02:00
using System;
2016-05-17 18:22:18 +02:00
namespace Yavsc.Controllers
{
2016-11-07 19:34:56 +01:00
[ServiceFilter(typeof(LanguageActionFilter)),
2016-05-17 18:22:18 +02:00
Route("do")]
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 latestPosts = _context.Blogspot.Where(
2016-08-02 17:02:38 +02:00
x => x.Visible == true
).OrderBy(x => x.Modified).Take(25).ToArray();
2016-05-17 18:22:18 +02:00
return View(latestPosts);
}
2016-11-07 19:34:56 +01:00
[Route("Book/{id?}"), HttpGet]
2016-05-17 18:22:18 +02:00
public ActionResult Book(string id)
{
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");
}
2016-11-07 19:34:56 +01:00
2016-05-17 18:22:18 +02:00
ViewBag.Activities = _context.ActivityItems(id);
2016-11-07 19:34:56 +01:00
ViewBag.Activity = _context.Activities.FirstOrDefault(
a => a.Code == id);
2016-05-17 18:22:18 +02:00
return View(
2016-11-07 19:34:56 +01:00
_context.Performers.Include(p => p.Performer).Where
2016-05-17 18:22:18 +02:00
(p => p.ActivityCode == id && p.Active).OrderBy(
2016-11-07 19:34:56 +01:00
x => x.MinDailyCost
2016-05-17 18:22:18 +02:00
)
);
}
2016-11-07 19:34:56 +01:00
[Route("Book/{id}"), HttpPost]
2016-05-17 18:22:18 +02:00
public ActionResult Book(BookQuery bookQuery)
{
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);
}
_context.SaveChanges();
// TODO Send sys notifications &
// notify the user (make him a basket badge)
return View("Index");
}
ViewBag.Activities = _context.ActivityItems(null);
2016-11-07 19:34:56 +01:00
return View(_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
[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)
.Include(e => e.Bill).FirstOrDefault(x => x.Id == id);
if (estimate==null)
throw new Exception("No data");
return View("Estimate.pdf",estimate);
2016-11-06 02:03:36 +01:00
}
2016-11-07 19:34:56 +01:00
}
2016-11-09 14:03:57 +01:00
}