yavsc/Yavsc/Controllers/FrontOfficeController.cs

116 lines
4 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
{
[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);
}
[Route("Book/{id?}"),HttpGet]
public ActionResult Book(string id)
{
2016-08-01 01:43:15 +02:00
if (id == null) {
throw new NotImplementedException("No Activity code");
}
2016-05-17 18:22:18 +02:00
ViewBag.Activities = _context.ActivityItems(id);
ViewBag.Activity = _context.Activities.FirstOrDefault(
2016-08-01 01:43:15 +02:00
a => a.Code == id );
2016-05-17 18:22:18 +02:00
return View(
_context.Performers.Include(p=>p.Performer).Where
(p => p.ActivityCode == id && p.Active).OrderBy(
x=>x.MinDailyCost
)
);
}
[Route("Book/{id}"),HttpPost]
public ActionResult Book(BookQuery bookQuery)
{
if (ModelState.IsValid) {
var pro = _context.Performers.Include(
pr => pr.Performer
).FirstOrDefault(
2016-07-27 11:08:45 +02:00
x=>x.PerformerId == bookQuery.PerformerId
2016-05-17 18:22:18 +02:00
);
if (pro==null)
return HttpNotFound();
// Let's create a command
if (bookQuery.Id==0)
{
_context.BookQueries.Add(bookQuery);
}
else {
_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);
return View( _context.Performers.Include(p=>p.Performer).Where
(p => p.Active).OrderBy(
x=>x.MinDailyCost
));
}
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-03 17:34:19 +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);
Response.ContentType = "text/x-tex";
return View("Estimate.tex", estimate);
2016-05-17 18:22:18 +02:00
}
2016-11-06 02:03:36 +01:00
[Produces("application/x-pdf"), Authorize, Route("estimate-{id}.pdf")]
public ViewResult EstimatePdf(long id)
{
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);
return View("Estimate.pdf", estimate);
}
2016-05-17 18:22:18 +02:00
}
}