une commande de coupe de cheveux
This commit is contained in:
parent
27b26f0545
commit
c001994d50
38 changed files with 3137 additions and 196 deletions
|
|
@ -21,6 +21,7 @@ namespace Yavsc.Controllers
|
|||
using Microsoft.AspNet.Http;
|
||||
using Yavsc.Extensions;
|
||||
using Yavsc.Models.Haircut;
|
||||
using System.Globalization;
|
||||
|
||||
public class HairCutCommandController : CommandController
|
||||
{
|
||||
|
|
@ -40,10 +41,10 @@ namespace Yavsc.Controllers
|
|||
|
||||
[HttpPost, Authorize]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> CreateHairCutQuery(HairCutQuery command)
|
||||
public async Task<IActionResult> CreateHairCutQuery(HairCutQuery model)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var prid = command.PerformerId;
|
||||
var prid = model.PerformerId;
|
||||
if (string.IsNullOrWhiteSpace(uid)
|
||||
|| string.IsNullOrWhiteSpace(prid))
|
||||
throw new InvalidOperationException(
|
||||
|
|
@ -53,39 +54,43 @@ namespace Yavsc.Controllers
|
|||
u => u.Performer
|
||||
).Include(u => u.Performer.Devices)
|
||||
.FirstOrDefault(
|
||||
x => x.PerformerId == command.PerformerId
|
||||
x => x.PerformerId == model.PerformerId
|
||||
);
|
||||
var user = await _userManager.FindByIdAsync(uid);
|
||||
command.Client = user;
|
||||
command.ClientId = uid;
|
||||
command.PerformerProfile = pro;
|
||||
model.PerformerProfile = pro;
|
||||
// FIXME Why!!
|
||||
// ModelState.ClearValidationState("PerformerProfile.Avatar");
|
||||
// ModelState.ClearValidationState("Client.Avatar");
|
||||
// ModelState.ClearValidationState("ClientId");
|
||||
ModelState.MarkFieldSkipped("ClientId");
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var existingLocation = _context.Locations.FirstOrDefault( x=>x.Address == command.Location.Address
|
||||
&& x.Longitude == command.Location.Longitude && x.Latitude == command.Location.Latitude );
|
||||
if (model.Location!=null) {
|
||||
var existingLocation = await _context.Locations.FirstOrDefaultAsync( x=>x.Address == model.Location.Address
|
||||
&& x.Longitude == model.Location.Longitude && x.Latitude == model.Location.Latitude );
|
||||
|
||||
if (existingLocation!=null) {
|
||||
command.Location=existingLocation;
|
||||
}
|
||||
else _context.Attach<Location>(command.Location);
|
||||
if (existingLocation!=null) {
|
||||
model.Location=existingLocation;
|
||||
}
|
||||
else _context.Attach<Location>(model.Location);
|
||||
}
|
||||
var existingPrestation = await _context.HairPrestation.FirstOrDefaultAsync( x=> model.PrestationId == x.Id );
|
||||
|
||||
_context.HairCutQueries.Add(command, GraphBehavior.IncludeDependents);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
if (existingPrestation!=null) {
|
||||
model.Prestation = existingPrestation;
|
||||
}
|
||||
else _context.Attach<HairPrestation>(model.Prestation);
|
||||
|
||||
var yaev = command.CreateEvent(_localizer);
|
||||
_context.HairCutQueries.Add(model);
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
var brusherProfile = await _context.BrusherProfile.SingleAsync(p=>p.UserId == pro.PerformerId);
|
||||
var yaev = model.CreateEvent(_localizer);
|
||||
MessageWithPayloadResponse grep = null;
|
||||
|
||||
if (pro.AcceptPublicContact)
|
||||
{
|
||||
if (pro.AcceptNotifications) {
|
||||
if (pro.Performer.Devices.Count > 0) {
|
||||
var regids = command.PerformerProfile.Performer
|
||||
var regids = model.PerformerProfile.Performer
|
||||
.Devices.Select(d => d.GCMRegistrationId);
|
||||
grep = await _GCMSender.NotifyHairCutQueryAsync(_googleSettings,regids,yaev);
|
||||
}
|
||||
|
|
@ -94,12 +99,12 @@ namespace Yavsc.Controllers
|
|||
// if (grep==null || grep.success<=0 || grep.failure>0)
|
||||
ViewBag.GooglePayload=grep;
|
||||
if (grep!=null)
|
||||
_logger.LogWarning($"Performer: {command.PerformerProfile.Performer.UserName} success: {grep.success} failure: {grep.failure}");
|
||||
_logger.LogWarning($"Performer: {model.PerformerProfile.Performer.UserName} success: {grep.success} failure: {grep.failure}");
|
||||
}
|
||||
|
||||
await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
model.PerformerProfile.Performer.Email,
|
||||
yaev.Topic+" "+yaev.Sender,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
|
|
@ -107,16 +112,19 @@ namespace Yavsc.Controllers
|
|||
else {
|
||||
// TODO if (AcceptProContact) try & find a bookmaker to send him this query
|
||||
}
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode);
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == model.ActivityCode);
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View("CommandConfirmation",command);
|
||||
var addition = model.Prestation.Addition(brusherProfile);
|
||||
ViewBag.Addition = addition.ToString("C",CultureInfo.CurrentUICulture);
|
||||
return View("CommandConfirmation",model);
|
||||
}
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode);
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == model.ActivityCode);
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View(command);
|
||||
SetViewData(model.ActivityCode,model.PerformerId,model.Prestation);
|
||||
return View("HairCut",model);
|
||||
}
|
||||
|
||||
public ActionResult HairCut(string performerId, string activityCode)
|
||||
public async Task<ActionResult> HairCut(string performerId, string activityCode)
|
||||
{
|
||||
HairPrestation pPrestation=null;
|
||||
var prestaJson = HttpContext.Session.GetString("HairCutPresta") ;
|
||||
|
|
@ -125,6 +133,26 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
else pPrestation = new HairPrestation {};
|
||||
|
||||
var uid = User.GetUserId();
|
||||
var user = await _userManager.FindByIdAsync(uid);
|
||||
|
||||
SetViewData(activityCode,performerId,pPrestation);
|
||||
|
||||
var perfer = _context.Performers.Include(
|
||||
p=>p.Performer
|
||||
).Single(p=>p.PerformerId == performerId);
|
||||
var result = new HairCutQuery {
|
||||
PerformerProfile = perfer,
|
||||
PerformerId = perfer.PerformerId,
|
||||
ClientId = uid,
|
||||
Prestation = pPrestation,
|
||||
Client = user
|
||||
};
|
||||
|
||||
return View(result);
|
||||
}
|
||||
private void SetViewData (string activityCode, string performerId, HairPrestation pPrestation )
|
||||
{
|
||||
ViewBag.HairTaints = _context.HairTaint.Include(t=>t.Color);
|
||||
ViewBag.HairTechnos = EnumExtensions.GetSelectList(typeof(HairTechnos),_localizer);
|
||||
ViewBag.HairLength = EnumExtensions.GetSelectList(typeof(HairLength),_localizer);
|
||||
|
|
@ -135,16 +163,6 @@ namespace Yavsc.Controllers
|
|||
|| pPrestation.Tech == HairTechnos.Mech ) ? "":"hidden";
|
||||
ViewBag.TechClass = ( pPrestation.Gender == HairCutGenders.Women ) ? "":"hidden";
|
||||
ViewData["PerfPrefs"] = _context.BrusherProfile.Single(p=>p.UserId == performerId);
|
||||
var perfer = _context.Performers.Include(
|
||||
p=>p.Performer
|
||||
).Single(p=>p.PerformerId == performerId);
|
||||
var result = new HairCutQuery {
|
||||
PerformerProfile = perfer,
|
||||
PerformerId = perfer.PerformerId,
|
||||
ClientId = User.GetUserId(),
|
||||
Prestation = pPrestation
|
||||
};
|
||||
return View(result);
|
||||
}
|
||||
|
||||
[HttpPost, Authorize]
|
||||
|
|
@ -219,7 +237,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode);
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View(command);
|
||||
return View("HairCut",command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
public HairPrestationsController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: HairPrestations
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace Yavsc.Controllers
|
|||
using Models.Relationship;
|
||||
using PayPal.PayPalAPIInterfaceService;
|
||||
using PayPal.PayPalAPIInterfaceService.Model;
|
||||
using Yavsc.Models.Bank;
|
||||
|
||||
[Authorize]
|
||||
public class ManageController : Controller
|
||||
|
|
@ -88,6 +89,8 @@ namespace Yavsc.Controllers
|
|||
: message == ManageMessageId.SetActivitySuccess ? _SR["Your activity was set."]
|
||||
: message == ManageMessageId.AvatarUpdateSuccess ? _SR["Your avatar was updated."]
|
||||
: message == ManageMessageId.IdentityUpdateSuccess ? _SR["Your identity was updated."]
|
||||
: message == ManageMessageId.SetBankInfoSuccess ? _SR["Vos informations bancaires ont bien été enregistrées."]
|
||||
: message == ManageMessageId.SetAddressSuccess ? _SR["Votre adresse a bien été enregistrée."]
|
||||
: "";
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
|
|
@ -265,7 +268,7 @@ namespace Yavsc.Controllers
|
|||
return View();
|
||||
}
|
||||
|
||||
[HttpGet, Authorize]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> SetGoogleCalendar(string returnUrl)
|
||||
{
|
||||
var credential = await _userManager.GetCredentialForGoogleApiAsync(
|
||||
|
|
@ -290,8 +293,7 @@ namespace Yavsc.Controllers
|
|||
return View(new SetGoogleCalendarViewModel { ReturnUrl = returnUrl });
|
||||
}
|
||||
|
||||
[HttpPost, ValidateAntiForgeryToken,
|
||||
Authorize]
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> SetGoogleCalendar(SetGoogleCalendarViewModel model)
|
||||
{
|
||||
var user = _dbContext.Users.FirstOrDefault(u => u.Id == User.GetUserId());
|
||||
|
|
@ -302,16 +304,41 @@ namespace Yavsc.Controllers
|
|||
else return Redirect(model.ReturnUrl);
|
||||
}
|
||||
|
||||
[HttpGet,Authorize]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> AddBankInfo()
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
||||
var uid = User.GetUserId();
|
||||
var user = await _dbContext.Users.Include(u=>u.BankInfo).SingleAsync(u=>u.Id==uid);
|
||||
|
||||
return View(new AddBankInfoViewModel(
|
||||
user.BankInfo));
|
||||
return View(user.BankInfo);
|
||||
}
|
||||
|
||||
[HttpGet,Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddBankInfo (BankIdentity model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// TODO PostBankInfoRequirement & auth
|
||||
var uid = User.GetUserId();
|
||||
var user = _dbContext.Users.Include(u=>u.BankInfo)
|
||||
.Single(u=>u.Id == uid);
|
||||
|
||||
if (user.BankInfo != null)
|
||||
{
|
||||
model.Id = user.BankInfo.Id;
|
||||
_dbContext.Entry(user.BankInfo).State = EntityState.Detached;
|
||||
_dbContext.Update(model);
|
||||
}
|
||||
else {
|
||||
user.BankInfo = model;
|
||||
_dbContext.Update(user);
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetBankInfoSuccess });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> SetFullName()
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
||||
|
|
@ -483,13 +510,13 @@ namespace Yavsc.Controllers
|
|||
return RedirectToAction(nameof(ManageLogins), new { Message = message });
|
||||
}
|
||||
|
||||
[HttpGet, Authorize]
|
||||
[HttpGet]
|
||||
public IActionResult SetAvatar()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet, Authorize]
|
||||
[HttpGet]
|
||||
public IActionResult SetActivity()
|
||||
{
|
||||
var user = GetCurrentUserAsync().Result;
|
||||
|
|
@ -520,7 +547,6 @@ namespace Yavsc.Controllers
|
|||
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> SetActivity(PerformerProfile model)
|
||||
{
|
||||
var user = GetCurrentUserAsync().Result;
|
||||
|
|
@ -588,7 +614,7 @@ namespace Yavsc.Controllers
|
|||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> UnsetActivity()
|
||||
{
|
||||
var user = GetCurrentUserAsync().Result;
|
||||
|
|
@ -784,6 +810,9 @@ namespace Yavsc.Controllers
|
|||
UnsetActivitySuccess,
|
||||
AvatarUpdateSuccess,
|
||||
IdentityUpdateSuccess,
|
||||
SetBankInfoSuccess,
|
||||
|
||||
SetAddressSuccess,
|
||||
Error
|
||||
}
|
||||
|
||||
|
|
@ -794,5 +823,36 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[HttpGet]
|
||||
public async Task <IActionResult> SetAddress()
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var user = await _dbContext.Users.Include(u=>u.PostalAddress).SingleAsync(u=>u.Id==uid);
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View(user.PostalAddress);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task <IActionResult> SetAddress(Location model)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
var uid = User.GetUserId();
|
||||
|
||||
var user = _dbContext.Users.Include(u=>u.PostalAddress).Single(u=>u.Id==uid);
|
||||
|
||||
var existingLocation = _dbContext.Locations.FirstOrDefault( x=>x.Address == model.Address
|
||||
&& x.Longitude == model.Longitude && x.Latitude == model.Latitude );
|
||||
|
||||
if (existingLocation!=null) {
|
||||
user.PostalAddressId = existingLocation.Id;
|
||||
} else _dbContext.Attach<Location>(model);
|
||||
user.PostalAddress = model;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetAddressSuccess });
|
||||
}
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue