refabrique des commandes

This commit is contained in:
Paul Schneider 2016-06-14 03:37:57 +02:00
commit 6bf8c8da65
38 changed files with 2479 additions and 257 deletions

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;

View file

@ -30,7 +30,7 @@ namespace Yavsc.Controllers
SmtpSettings _smtpSettings;
private readonly ILogger _logger;
public CommandController(ApplicationDbContext context,IOptions<GoogleAuthSettings> googleSettings,
public CommandController(ApplicationDbContext context, IOptions<GoogleAuthSettings> googleSettings,
IGoogleCloudMessageSender GCMSender,
UserManager<ApplicationUser> userManager,
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer,
@ -54,11 +54,11 @@ namespace Yavsc.Controllers
public IActionResult Index()
{
return View(_context.BookQueries
.Include(x=>x.Client)
.Include(x=>x.PerformerProfile)
.Include(x=>x.PerformerProfile.Performer)
.Include(x=>x.Location)
.Include(x=>x.Bill).ToList());
.Include(x => x.Client)
.Include(x => x.PerformerProfile)
.Include(x => x.PerformerProfile.Performer)
.Include(x => x.Location)
.Include(x => x.Bill).ToList());
}
// GET: Command/Details/5
@ -70,8 +70,8 @@ namespace Yavsc.Controllers
}
BookQuery command = _context.BookQueries
.Include(x=>x.Location)
.Include(x=>x.PerformerProfile)
.Include(x => x.Location)
.Include(x => x.PerformerProfile)
.Single(m => m.Id == id);
if (command == null)
{
@ -90,66 +90,79 @@ namespace Yavsc.Controllers
/// <returns></returns>
public IActionResult Create(string id)
{
if (string.IsNullOrWhiteSpace(id))
throw new InvalidOperationException(
"This method needs a performer id"
);
var pro = _context.Performers.Include(
x=>x.Performer).FirstOrDefault(
x=>x.PerfomerId == id
x => x.Performer).FirstOrDefault(
x => x.PerfomerId == id
);
if (pro==null)
if (pro == null)
return HttpNotFound();
ViewBag.GoogleSettings = _googleSettings;
var userid = User.GetUserId();
var user = _userManager.FindByIdAsync(userid).Result;
return View(new BookQuery{
var user = _userManager.FindByIdAsync(userid).Result;
return View(new BookQuery(new Location(),DateTime.Now.AddHours(4))
{
PerformerProfile = pro,
PerformerId = pro.PerfomerId,
ClientId = userid,
Client = user,
Location = new Location(),
EventDate = DateTime.Now.AddHours(4)
Client = user
});
}
// POST: Command/Create
[HttpPost]
[HttpPost, Authorize]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(BookQuery command)
{
var pro = _context.Performers.FirstOrDefault(
x=>x.PerfomerId == command.PerformerId
var uid = User.GetUserId();
var prid = command.PerformerId;
if (string.IsNullOrWhiteSpace(uid)
|| string.IsNullOrWhiteSpace(prid))
throw new InvalidOperationException(
"This method needs a prid and uid"
);
var pro = _context.Performers.Include(
u => u.Performer
).Include( u => u.Performer.Devices)
.FirstOrDefault(
x => x.PerfomerId == command.PerformerId
);
command.PerformerProfile = pro;
var user = _userManager.FindByIdAsync(
User.GetUserId()
).Result;
var user = await _userManager.FindByIdAsync(
User.GetUserId()
);
command.Client = user;
if (ModelState.IsValid)
{
var yaev = command.CreateEvent(_localizer);
MessageWithPayloadResponse grep=null;
MessageWithPayloadResponse grep = null;
_context.Attach<Location>(command.Location);
_context.BookQueries.Add(command,GraphBehavior.IncludeDependents);
_context.BookQueries.Add(command, GraphBehavior.IncludeDependents);
_context.SaveChanges();
if (command.PerformerProfile.AcceptNotifications
&& command.PerformerProfile.AcceptPublicContact
&& command.PerformerProfile.Performer.Devices.Select(d=>d.RegistrationId)!=null) {
grep = await _GCMSender.NotifyAsync(_googleSettings,
command.PerformerProfile.Performer.Devices.Select(d=>d.RegistrationId),
yaev
);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
// if (grep==null || grep.success<=0 || grep.failure>0)
if (pro.AcceptNotifications
&& pro.AcceptPublicContact)
{
if (pro.Performer.Devices.Count > 0)
grep = await _GCMSender.NotifyAsync(_googleSettings,
command.PerformerProfile.Performer.Devices.Select(d => d.RegistrationId),
yaev
);
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
// if (grep==null || grep.success<=0 || grep.failure>0)
await _emailSender.SendEmailAsync(
_siteSettings, _smtpSettings,
command.PerformerProfile.Performer.Email,
yaev.Title,
$"{yaev.Description}\r\n-- \r\n{yaev.Comment}\r\n"
);
}
return RedirectToAction("Index");
}

View file

@ -8,6 +8,7 @@ using Microsoft.Data.Entity;
using Microsoft.Extensions.OptionsModel;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Billing;
namespace Yavsc.Controllers
{
@ -36,10 +37,10 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
Estimate estimate = _context.Estimates
.Include(e => e.Command)
.Include(e => e.Command.PerformerProfile)
.Include(e => e.Command.PerformerProfile.Performer)
RDVEstimate estimate = _context.Estimates
.Include(e => e.Query)
.Include(e => e.Query.PerformerProfile)
.Include(e => e.Query.PerformerProfile.Performer)
.Single(m => m.Id == id);
if (estimate == null)
{
@ -60,7 +61,7 @@ namespace Yavsc.Controllers
// POST: Estimate/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Estimate estimate,
public IActionResult Create(RDVEstimate estimate,
ICollection<IFormFile> newGraphics,
ICollection<IFormFile> newFiles
)
@ -74,9 +75,9 @@ namespace Yavsc.Controllers
var perfomerProfile = _context.Performers
.Include(
perpr => perpr.Performer).FirstOrDefault(
x=>x.PerfomerId == estimate.Command.PerformerId
x=>x.PerfomerId == estimate.Query.PerformerId
);
var command = _context.Commands.FirstOrDefault(
var command = _context.BookQueries.FirstOrDefault(
cmd => cmd.Id == estimate.CommandId
);
@ -114,7 +115,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
if (estimate == null)
{
return HttpNotFound();
@ -126,7 +127,7 @@ namespace Yavsc.Controllers
// POST: Estimate/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(Estimate estimate)
public IActionResult Edit(RDVEstimate estimate)
{
if (ModelState.IsValid)
{
@ -146,7 +147,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
if (estimate == null)
{
return HttpNotFound();
@ -160,7 +161,7 @@ namespace Yavsc.Controllers
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(long id)
{
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
_context.Estimates.Remove(estimate);
_context.SaveChanges();
return RedirectToAction("Index");

View file

@ -7,6 +7,7 @@ using Microsoft.Data.Entity;
using Microsoft.Extensions.Logging;
using Yavsc.Models.Booking;
using Yavsc.Helpers;
using Yavsc.Models.Billing;
namespace Yavsc.Controllers
{
@ -94,11 +95,11 @@ namespace Yavsc.Controllers
[Produces("text/x-tex"), Authorize,
Route("Release/Estimate-{id}.tex")]
public Estimate Estimate(long id)
public RDVEstimate Estimate(long id)
{
var estimate = _context.Estimates.Include(x=>x.Command).
Include(x=>x.Command.Client).FirstOrDefault(x=>x.Id==id);
var adc = estimate.Command.Client.UserName;
var estimate = _context.Estimates.Include(x=>x.Query).
Include(x=>x.Query.Client).FirstOrDefault(x=>x.Id==id);
var adc = estimate.Query.Client.UserName;
return estimate;
}
}

View file

@ -18,6 +18,7 @@ using Yavsc.Helpers;
using Yavsc.ViewModels.Calendar;
using System.Net;
using Microsoft.Extensions.Localization;
using Yavsc.Models.Workflow;
namespace Yavsc.Controllers
{