yavsc/Yavsc/Helpers/EventHelpers.cs

110 lines
3.7 KiB
C#
Raw Normal View History

2016-05-17 18:22:18 +02:00
using Microsoft.Extensions.Localization;
namespace Yavsc.Helpers
{
2017-02-11 15:46:26 +01:00
using Models.Workflow;
using Models.Messaging;
2017-02-27 19:28:32 +01:00
using Yavsc.Models.Haircut;
2017-05-15 15:36:46 +02:00
using System.Linq;
2017-05-28 06:14:36 +02:00
using System.Globalization;
2017-02-27 19:28:32 +01:00
2016-05-17 18:22:18 +02:00
public static class EventHelpers
{
2017-02-27 19:28:32 +01:00
public static RdvQueryEvent CreateEvent(this RdvQuery query,
2016-05-17 18:22:18 +02:00
IStringLocalizer SR)
{
2017-02-27 19:28:32 +01:00
var yaev = new RdvQueryEvent
2017-04-01 02:14:10 +02:00
{
2017-02-27 19:28:32 +01:00
Sender = query.ClientId,
Message = string.Format(SR["RdvToPerf"],
query.Client.UserName,
query.EventDate.ToString("dddd dd/MM/yyyy à HH:mm"),
query.Location.Address,
query.ActivityCode)+
"\n"+query.Reason,
Client = new ClientProviderInfo { 
2017-04-01 02:14:10 +02:00
UserName = query.Client.UserName ,
UserId = query.ClientId,
Avatar = query.Client.Avatar } ,
2016-09-17 03:36:34 +02:00
Previsional = query.Previsional,
EventDate = query.EventDate,
Location = query.Location,
Id = query.Id,
2017-01-16 15:34:05 +01:00
Reason = query.Reason,
ActivityCode = query.ActivityCode
2016-05-17 18:22:18 +02:00
};
return yaev;
}
2017-02-27 19:28:32 +01:00
public static HairCutQueryEvent CreateEvent(this HairCutQuery query,
2017-04-08 09:17:15 +02:00
IStringLocalizer SR, BrusherProfile bpr)
2017-02-27 19:28:32 +01:00
{
2017-05-30 23:39:56 +02:00
2017-04-08 09:17:15 +02:00
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;
2017-05-28 06:14:36 +02:00
string total = query.GetBillItems().Addition().ToString("C",CultureInfo.CurrentUICulture);
2017-05-30 23:39:56 +02:00
string strprestation = query.GetDescription();
2017-05-15 15:36:46 +02:00
string bill = string.Join("\n", query.GetBillItems().Select(
2017-05-30 23:39:56 +02:00
l=> $"{l.Name} {l.Description} {l.UnitaryCost} € " +
((l.Count != 1) ? "*"+l.Count.ToString() : "")));
2017-02-27 19:28:32 +01:00
var yaev = new HairCutQueryEvent
2017-04-01 02:14:10 +02:00
{
2017-05-30 23:39:56 +02:00
Sender = $"{strprestation} pour {query.Client.UserName}",
Message =
$@"Un client vient de valider une demande de prestation à votre encontre:
Prestation: {strprestation}
Client : {query.Client.UserName}
Date: {evdate},
Adresse: {address}
2017-04-08 09:17:15 +02:00
-----
2017-05-30 23:39:56 +02:00
{query.AdditionalInfo}
Facture prévue (non réglée):
2017-04-08 09:17:15 +02:00
2017-05-15 15:36:46 +02:00
{bill}
2017-05-28 06:14:36 +02:00
2017-05-30 23:39:56 +02:00
Total: {total}
2017-04-08 09:17:15 +02:00
" ,
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,
2017-05-15 15:36:46 +02:00
Reason = $"{query.AdditionalInfo}",
2017-04-08 09:17:15 +02:00
ActivityCode = query.ActivityCode
2017-02-27 19:28:32 +01:00
};
return yaev;
}
public static HairCutQueryEvent CreateEvent(this HairMultiCutQuery query,
2017-04-08 09:17:15 +02:00
IStringLocalizer SR, BrusherProfile bpr)
2017-02-27 19:28:32 +01:00
{
var yaev = new HairCutQueryEvent
2017-04-01 02:14:10 +02:00
{
2017-02-27 19:28:32 +01:00
Sender = query.ClientId,
Message = string.Format(SR["RdvToPerf"],
query.Client.UserName,
query.EventDate.ToString("dddd dd/MM/yyyy à HH:mm"),
query.Location.Address,
query.ActivityCode),
Client = new ClientProviderInfo { 
2017-04-01 02:14:10 +02:00
UserName = query.Client.UserName ,
UserId = query.ClientId,
2017-02-27 19:28:32 +01:00
Avatar = query.Client.Avatar } ,
Previsional = query.Previsional,
EventDate = query.EventDate,
Location = query.Location,
Id = query.Id,
Reason = "Commande groupée!",
ActivityCode = query.ActivityCode
};
return yaev;
}
2016-05-17 18:22:18 +02:00
}
}