refactoring the haircut messaging
This commit is contained in:
@ -5,7 +5,7 @@ namespace Yavsc.Interfaces.Workflow {
|
||||
/// <c>/topic/(bookquery|estimate)</c>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string Topic { get; set ; }
|
||||
string Topic { get; }
|
||||
/// <summary>
|
||||
/// Should be the user's name
|
||||
/// </summary>
|
||||
|
@ -158,7 +158,8 @@ namespace Yavsc.Controllers
|
||||
_context.RdvQueries.Add(command, GraphBehavior.IncludeDependents);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
var yaev = command.CreateEvent(_localizer);
|
||||
var yaev = command.CreateEvent(_localizer, "NewCommand");
|
||||
|
||||
MessageWithPayloadResponse grep = null;
|
||||
|
||||
if (pro.AcceptNotifications
|
||||
@ -173,13 +174,11 @@ namespace Yavsc.Controllers
|
||||
// both on mailbox and mobile
|
||||
// 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}");
|
||||
|
||||
await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
yaev.Topic+" "+yaev.Sender,
|
||||
$"{command.Client.UserName} (un client) vous demande un rendez-vous",
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Yavsc.Controllers
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using System.Collections.Generic;
|
||||
using Yavsc.Models.Messaging;
|
||||
using PayPal.PayPalAPIInterfaceService.Model;
|
||||
|
||||
public class HairCutCommandController : CommandController
|
||||
{
|
||||
@ -47,13 +48,16 @@ namespace Yavsc.Controllers
|
||||
|
||||
private async Task<HairCutQuery> GetQuery(long id)
|
||||
{
|
||||
return await _context.HairCutQueries
|
||||
var query = await _context.HairCutQueries
|
||||
.Include(x => x.Location)
|
||||
.Include(x => x.PerformerProfile)
|
||||
.Include(x => x.Prestation)
|
||||
.Include(x => x.PerformerProfile.Performer)
|
||||
.Include(x => x.PerformerProfile.Performer.Devices)
|
||||
.Include(x => x.Regularisation)
|
||||
.SingleAsync(m => m.Id == id);
|
||||
query.SelectedProfile = await _context.BrusherProfile.SingleAsync(b=>b.UserId == query.PerformerId);
|
||||
return query;
|
||||
}
|
||||
public async Task<IActionResult> ClientCancel(long id)
|
||||
{
|
||||
@ -76,16 +80,82 @@ namespace Yavsc.Controllers
|
||||
ViewData["paymentinfo"] = paymentInfo;
|
||||
command.Regularisation = paymentInfo.DbContent;
|
||||
command.PaymentId = token;
|
||||
if (paymentInfo!=null)
|
||||
if (paymentInfo.DetailsFromPayPal!=null)
|
||||
if (paymentInfo.DetailsFromPayPal.Ack == AckCodeType.SUCCESS)
|
||||
if (command.ValidationDate ==null)
|
||||
command.ValidationDate = DateTime.Now;
|
||||
await _context.SaveChangesAsync (User.GetUserId());
|
||||
|
||||
SetViewBagPaymentUrls(id);
|
||||
if (command.PerformerProfile.AcceptPublicContact)
|
||||
{
|
||||
var invoiceId = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.InvoiceID;
|
||||
var payerName = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Name;
|
||||
var phone = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Phone;
|
||||
var payerEmail = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
|
||||
var amount = string.Join(", ",
|
||||
paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PaymentDetails.Select(
|
||||
p=> $"{p.OrderTotal.value} {p.OrderTotal.currencyID}"));
|
||||
var gender = command.Prestation.Gender;
|
||||
var date = command.EventDate?.ToString("dd MM yyyy hh:mm");
|
||||
var lieu = command.Location.Address;
|
||||
string clientFinal = (gender == HairCutGenders.Women) ? _localizer["Women"] +
|
||||
" "+_localizer[command.Prestation.Length.ToString()] : _localizer[gender.ToString()] ;
|
||||
MessageWithPayloadResponse grep = null;
|
||||
var yaev = command.CreateEvent("PaymentConfirmation",
|
||||
this._localizer["PaymentConfirmation"],
|
||||
command.Client.GetSender(),
|
||||
$@"# Paiment confirmé: {amount}
|
||||
|
||||
Effectué par : {payerName} [{payerEmail}]
|
||||
Identifiant PayPal du paiment: {token}
|
||||
Identifiant PayPal du payeur: {PayerID}
|
||||
Identifiant de la facture sur site: {invoiceId}
|
||||
|
||||
|
||||
# La prestation concernée:
|
||||
|
||||
Demandeur: {command.Client.UserName}
|
||||
|
||||
Date: {date}
|
||||
|
||||
Lieu: {lieu}
|
||||
|
||||
Le client final: {clientFinal}
|
||||
|
||||
{command.GetBillText()}
|
||||
|
||||
");
|
||||
|
||||
if (command.PerformerProfile.AcceptNotifications) {
|
||||
if (command.PerformerProfile.Performer.Devices.Count > 0) {
|
||||
var regids = command.PerformerProfile.Performer
|
||||
.Devices.Select(d => d.GCMRegistrationId);
|
||||
grep = await _GCMSender.NotifyHairCutQueryAsync(_googleSettings,regids,yaev);
|
||||
}
|
||||
// TODO setup a profile choice to allow notifications
|
||||
// both on mailbox and mobile
|
||||
// if (grep==null || grep.success<=0 || grep.failure>0)
|
||||
ViewBag.GooglePayload=grep;
|
||||
}
|
||||
|
||||
ViewBag.EmailSent = await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
yaev.Reason,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
else {
|
||||
// TODO if (AcceptProContact) try & find a bookmaker to send him this query
|
||||
}
|
||||
|
||||
ViewData ["Notify"] = new List<Notification> {
|
||||
new Notification {
|
||||
title= "Paiment PayPal",
|
||||
body = "Votre paiment a été accépté."
|
||||
}
|
||||
} ;
|
||||
|
||||
return View ("Details",command);
|
||||
}
|
||||
|
||||
@ -213,7 +283,7 @@ namespace Yavsc.Controllers
|
||||
var brusherProfile = await _context.BrusherProfile.SingleAsync(p=>p.UserId == pro.PerformerId);
|
||||
model.Client = await _context.Users.SingleAsync(u=>u.Id == model.ClientId);
|
||||
model.SelectedProfile = brusherProfile;
|
||||
var yaev = model.CreateEvent(_localizer, brusherProfile);
|
||||
var yaev = model.CreateNewHairCutQueryEvent(_localizer);
|
||||
MessageWithPayloadResponse grep = null;
|
||||
|
||||
if (pro.AcceptPublicContact)
|
||||
@ -235,7 +305,7 @@ namespace Yavsc.Controllers
|
||||
await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
model.PerformerProfile.Performer.Email,
|
||||
yaev.Topic,
|
||||
yaev.Reason,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Yavsc.Billing;
|
||||
using Yavsc.Models.Billing;
|
||||
@ -11,5 +12,11 @@ namespace Yavsc.Helpers
|
||||
|
||||
public static decimal Addition(this List<CommandLine> items) => items.Select(i=>((IBillItem)i)).ToList().Addition();
|
||||
|
||||
public static string GetBillText(this IBillable query) {
|
||||
string total = query.GetBillItems().Addition().ToString("C", CultureInfo.CurrentUICulture);
|
||||
string bill = string.Join("\n", query.GetBillItems().Select(l=> $"{l.Name} {l.Description} : {l.UnitaryCost} € " + ((l.Count != 1) ? "*"+l.Count.ToString() : ""))) +
|
||||
$"\n\nTotal: {total}";
|
||||
return bill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,14 @@ namespace Yavsc.Helpers
|
||||
using Models.Workflow;
|
||||
using Models.Messaging;
|
||||
using Yavsc.Models.Haircut;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using Yavsc.Models;
|
||||
|
||||
public static class EventHelpers
|
||||
{
|
||||
public static RdvQueryEvent CreateEvent(this RdvQuery query,
|
||||
IStringLocalizer SR)
|
||||
IStringLocalizer SR, string subtopic)
|
||||
{
|
||||
var yaev = new RdvQueryEvent
|
||||
var yaev = new RdvQueryEvent(subtopic)
|
||||
{
|
||||
Sender = query.ClientId,
|
||||
Message = string.Format(SR["RdvToPerf"],
|
||||
@ -30,30 +29,24 @@ namespace Yavsc.Helpers
|
||||
EventDate = query.EventDate,
|
||||
Location = query.Location,
|
||||
Id = query.Id,
|
||||
Reason = query.Reason,
|
||||
ActivityCode = query.ActivityCode
|
||||
};
|
||||
|
||||
return yaev;
|
||||
}
|
||||
public static HairCutQueryEvent CreateEvent(this HairCutQuery query,
|
||||
IStringLocalizer SR, BrusherProfile bpr)
|
||||
{
|
||||
|
||||
string evdate = query.EventDate?.ToString("dddd dd/MM/yyyy à HH:mm")??"[pas de date spécifiée]";
|
||||
|
||||
public static HairCutQueryEvent CreateNewHairCutQueryEvent(this HairCutQuery query,
|
||||
IStringLocalizer SR)
|
||||
{
|
||||
string evdate = query.EventDate?.ToString("dddd dd/MM/yyyy à hh:mm")??"[pas de date spécifiée]";
|
||||
string address = query.Location?.Address??"[pas de lieu spécifié]";
|
||||
var p = query.Prestation;
|
||||
string total = query.GetBillItems().Addition().ToString("C",CultureInfo.CurrentUICulture);
|
||||
string strprestation = query.GetDescription();
|
||||
string bill = string.Join("\n", query.GetBillItems().Select(
|
||||
l=> $"{l.Name} {l.Description} {l.UnitaryCost} € " +
|
||||
((l.Count != 1) ? "*"+l.Count.ToString() : "")));
|
||||
var yaev = new HairCutQueryEvent
|
||||
{
|
||||
Topic =
|
||||
string.Format(
|
||||
Startup.GlobalLocalizer["HairCutQueryValidation"],query.Client.UserName),
|
||||
Sender = $"{strprestation} pour {query.Client.UserName}",
|
||||
Message =
|
||||
|
||||
var yaev = query.CreateEvent("NewHairCutQuery",
|
||||
string.Format(Startup.GlobalLocalizer["HairCutQueryValidation"],query.Client.UserName),
|
||||
$"{query.Client.UserName}",
|
||||
$@"Un client vient de valider une demande de prestation à votre encontre:
|
||||
|
||||
Prestation: {strprestation}
|
||||
@ -66,29 +59,19 @@ $@"Un client vient de valider une demande de prestation à votre encontre:
|
||||
|
||||
Facture prévue (non réglée):
|
||||
|
||||
{bill}
|
||||
{query.GetBillText()}
|
||||
") ;
|
||||
|
||||
Total: {total}
|
||||
" ,
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = query.Client.UserName ,
|
||||
UserId = query.ClientId,
|
||||
Avatar = query.Client.Avatar } ,
|
||||
Previsional = query.Previsional,
|
||||
EventDate = query.EventDate,
|
||||
Location = query.Location,
|
||||
Id = query.Id,
|
||||
Reason = $"{query.AdditionalInfo}",
|
||||
ActivityCode = query.ActivityCode
|
||||
|
||||
};
|
||||
return yaev;
|
||||
}
|
||||
|
||||
public static string GetSender(this ApplicationUser user)
|
||||
{
|
||||
return user.UserName+" ["+user.Id+"@"+Startup.Authority+"]";
|
||||
}
|
||||
public static HairCutQueryEvent CreateEvent(this HairMultiCutQuery query,
|
||||
IStringLocalizer SR, BrusherProfile bpr)
|
||||
{
|
||||
var yaev = new HairCutQueryEvent
|
||||
var yaev = new HairCutQueryEvent("newCommand")
|
||||
{
|
||||
Sender = query.ClientId,
|
||||
Message = string.Format(SR["RdvToPerf"],
|
||||
|
@ -104,6 +104,8 @@ namespace Yavsc.Helpers
|
||||
}
|
||||
};
|
||||
|
||||
var d = new SetExpressCheckoutRequestDetailsType();
|
||||
|
||||
logger.LogInformation($"Creating express checkout for {Startup.PayPalSettings.MerchantAccountUserName} : "+JsonConvert.SerializeObject(coreq));
|
||||
var response = PayPalService.SetExpressCheckout( coreq, Startup.PayPalSettings.MerchantAccountUserName );
|
||||
|
||||
|
@ -6,6 +6,10 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Yavsc.Models.Billing;
|
||||
using Yavsc.Models.Relationship;
|
||||
using Yavsc.Billing;
|
||||
using System.Globalization;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models.Messaging;
|
||||
using System.Linq;
|
||||
|
||||
namespace Yavsc.Models.Haircut
|
||||
{
|
||||
@ -337,5 +341,33 @@ Prestation.Gender == HairCutGenders.Women ?
|
||||
|
||||
public virtual BrusherProfile SelectedProfile { get; set; }
|
||||
|
||||
public HairCutQueryEvent CreateEvent(string subTopic, string reason, string sender, string message) {
|
||||
|
||||
string evdate = EventDate?.ToString("dddd dd/MM/yyyy à HH:mm")??"[pas de date spécifiée]";
|
||||
string address = Location?.Address??"[pas de lieu spécifié]";
|
||||
var p = Prestation;
|
||||
string total = GetBillItems().Addition().ToString("C",CultureInfo.CurrentUICulture);
|
||||
string strprestation = GetDescription();
|
||||
string bill = string.Join("\n", GetBillItems().Select(
|
||||
l=> $"{l.Name} {l.Description} {l.UnitaryCost} € " +
|
||||
((l.Count != 1) ? "*"+l.Count.ToString() : "")));
|
||||
var yaev = new HairCutQueryEvent(subTopic)
|
||||
{
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = Client.UserName ,
|
||||
UserId =ClientId,
|
||||
Avatar = Client.Avatar } ,
|
||||
Previsional = Previsional,
|
||||
EventDate = EventDate,
|
||||
Location = Location,
|
||||
Id = Id,
|
||||
ActivityCode = ActivityCode,
|
||||
Reason = reason,
|
||||
Sender = sender,
|
||||
Message = message
|
||||
};
|
||||
return yaev;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ namespace Yavsc.Models.Haircut
|
||||
{
|
||||
public class HairCutQueryEvent : RdvQueryProviderInfo, IEvent
|
||||
{
|
||||
public HairCutQueryEvent()
|
||||
public HairCutQueryEvent(string subTopic)
|
||||
{
|
||||
Topic = "HairCutQuery";
|
||||
}
|
||||
|
||||
Topic = GetType().Name+"/"+subTopic;
|
||||
}
|
||||
public string Message
|
||||
{
|
||||
get;
|
||||
@ -27,7 +27,7 @@ namespace Yavsc.Models.Haircut
|
||||
{
|
||||
get;
|
||||
|
||||
set;
|
||||
private set;
|
||||
}
|
||||
|
||||
HairCutQuery Data { get; set; }
|
||||
|
@ -19,15 +19,13 @@
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
using Interfaces.Workflow;
|
||||
using Yavsc;
|
||||
|
||||
/// <summary>
|
||||
/// Base event.
|
||||
/// /// Base event.
|
||||
/// </summary>
|
||||
|
||||
public class BaseEvent : IEvent {
|
||||
@ -37,29 +35,12 @@ namespace Yavsc.Models.Messaging
|
||||
}
|
||||
public BaseEvent(string topic)
|
||||
{
|
||||
Topic = topic;
|
||||
Topic = GetType().Name+"/"+topic;
|
||||
}
|
||||
public string Topic { get; set; }
|
||||
public string Topic { get; private set; }
|
||||
public string Sender { get; set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class GeneralEvent: BaseEvent, ITitle
|
||||
{
|
||||
/// <summary>
|
||||
/// The title.
|
||||
/// </summary>
|
||||
[Required(ErrorMessageResourceName="ChooseATitle")]
|
||||
[Display(Name="Title")]
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// The description.
|
||||
/// </summary>
|
||||
[Required(ErrorMessageResourceName="ChooseADescription")]
|
||||
[Display(Name="Description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
43
Yavsc/Models/Messaging/GeneralEvent.cs
Normal file
43
Yavsc/Models/Messaging/GeneralEvent.cs
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// BaseEvent.cs
|
||||
//
|
||||
// Author:
|
||||
// Paul Schneider <paul@pschneider.fr>
|
||||
//
|
||||
// Copyright (c) 2015 GNU GPL
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
public class GeneralEvent: BaseEvent, ITitle
|
||||
{
|
||||
/// <summary>
|
||||
/// The title.
|
||||
/// </summary>
|
||||
[Required(ErrorMessageResourceName="ChooseATitle")]
|
||||
[Display(Name="Title")]
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// The description.
|
||||
/// </summary>
|
||||
[Required(ErrorMessageResourceName="ChooseADescription")]
|
||||
[Display(Name="Description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -27,9 +27,10 @@ using Interfaces.Workflow;
|
||||
|
||||
public class RdvQueryEvent: RdvQueryProviderInfo, IEvent
|
||||
{
|
||||
public RdvQueryEvent()
|
||||
|
||||
public RdvQueryEvent(string subTopic)
|
||||
{
|
||||
Topic = "RdvQuery";
|
||||
Topic = GetType().Name+"/"+subTopic;
|
||||
}
|
||||
|
||||
public string Message
|
||||
@ -44,7 +45,7 @@ public class RdvQueryEvent: RdvQueryProviderInfo, IEvent
|
||||
|
||||
public string Topic
|
||||
{
|
||||
get; set;
|
||||
get; private set;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,6 +308,7 @@
|
||||
<data name="Online"><value>En ligne</value></data>
|
||||
<data name="OnlyAuthorizedMayContact"><value>Seuls les utilisateurs authorisés peuvent contacter un préstataire par courrier.</value></data>
|
||||
<data name="Password"><value>Mot de passe</value></data>
|
||||
<data name="PaymentConfirmation"><value>Confirmation de paiement</value></data>
|
||||
<data name="Pdf version"><value>Version Pdf</value></data>
|
||||
<data name="PerformanceDate"><value>Date de la prestation</value></data>
|
||||
<data name="PerformancePlace"><value>Lieu de la pestation</value></data>
|
||||
|
Reference in New Issue
Block a user