yavsc/Yavsc.Server/Models/HairCut/HairCutQuery.cs

428 lines
18 KiB
C#
Raw Normal View History

2017-02-23 03:10:30 +01:00
2017-02-27 19:28:32 +01:00
using System;
2017-05-12 12:15:57 +02:00
using System.Collections.Generic;
2017-02-13 01:32:03 +01:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models.Billing;
2017-02-27 19:28:32 +01:00
using Yavsc.Models.Relationship;
2017-05-27 16:22:58 +02:00
using Yavsc.Billing;
2017-06-02 21:34:18 +02:00
using System.Globalization;
using Yavsc.Helpers;
using System.Linq;
2018-02-03 20:17:29 +01:00
using Microsoft.Extensions.Localization;
using Yavsc.ViewModels.PayPal;
using Yavsc.Models.HairCut;
2018-07-16 02:36:44 +02:00
using Yavsc.Abstract.Identity;
2017-02-13 01:32:03 +01:00
namespace Yavsc.Models.Haircut
{
2017-04-08 00:32:23 +02:00
public class HairCutQuery : NominativeServiceCommand
2017-02-13 01:32:03 +01:00
{
2017-05-12 12:15:57 +02:00
2017-05-05 23:37:07 +02:00
// Bill description
2018-08-01 10:55:52 +02:00
string _description = null;
public override string Description
2017-05-05 23:37:07 +02:00
{
2018-08-01 10:55:52 +02:00
get
{
string type = ResourcesHelpers.GlobalLocalizer[this.GetType().Name];
string gender = ResourcesHelpers.GlobalLocalizer[this.Prestation.Gender.ToString()];
return $"{_description} {type} ({gender})";
}
set
{
_description = value;
}
2018-08-01 03:12:08 +02:00
}
2017-05-30 23:42:04 +02:00
2017-05-05 23:37:07 +02:00
2017-02-13 01:32:03 +01:00
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2017-05-05 23:37:07 +02:00
override public long Id { get; set; }
2017-03-02 13:25:20 +01:00
[Required]
public long PrestationId { get; set; }
2017-05-12 12:15:57 +02:00
[ForeignKey("PrestationId"), Required, Display(Name = "Préstation")]
public virtual HairPrestation Prestation { get; set; }
2017-03-02 13:25:20 +01:00
2017-04-01 02:14:10 +02:00
[ForeignKey("LocationId")]
2017-05-12 12:15:57 +02:00
[Display(Name = "Lieu du rendez-vous")]
2017-04-08 17:51:31 +02:00
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Pas de lieu spécifié]")]
2017-05-12 12:15:57 +02:00
public virtual Location Location { get; set; }
2017-02-27 19:28:32 +01:00
2017-05-12 12:15:57 +02:00
[Display(Name = "Date et heure")]
[DisplayFormat(NullDisplayText = "[Pas de date ni heure]", ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? EventDate
2017-02-27 19:28:32 +01:00
{
get;
set;
}
2017-03-23 00:44:27 +01:00
2017-04-01 02:14:10 +02:00
public long? LocationId
2017-03-23 00:44:27 +01:00
{
get;
set;
}
2017-04-08 09:17:15 +02:00
2017-05-12 12:15:57 +02:00
[Display(Name = "Informations complémentaires"),
2017-04-08 09:17:15 +02:00
StringLengthAttribute(512)]
2017-04-08 17:51:31 +02:00
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[pas d'informations complémentaires]")]
2017-04-08 09:17:15 +02:00
public string AdditionalInfo { get; set; }
2017-05-12 12:15:57 +02:00
public override List<IBillItem> GetBillItems()
{
string longhairsuffix = " (cheveux longs)";
string halflonghairsuffix = " (cheveux mi-longs)";
string shorthairsuffix = " (cheveux courts)";
List<IBillItem> bill = new List<IBillItem>();
2018-08-01 10:55:52 +02:00
if (this.Prestation == null) throw new InvalidOperationException("Prestation property is null");
if (this.SelectedProfile == null) throw new InvalidOperationException("SelectedProfile property is null");
2017-05-12 12:15:57 +02:00
// Le shampoing
if (this.Prestation.Shampoo)
2018-08-01 10:55:52 +02:00
bill.Add(new CommandLine { Name = "Shampoing", Description = "Shampoing", UnitaryCost = SelectedProfile.ShampooPrice });
2017-05-12 12:15:57 +02:00
// la coupe
2018-08-01 10:55:52 +02:00
if (Prestation.Cut)
{
bill.Add(new CommandLine
2017-05-12 12:15:57 +02:00
{
2017-06-08 11:08:33 +02:00
2017-05-12 12:15:57 +02:00
Name = "Coupe",
2018-08-01 10:55:52 +02:00
Description = $"Coupe " +
ResourcesHelpers.GlobalLocalizer[Prestation.Gender.ToString()] + " " +
(Prestation.Gender == HairCutGenders.Women ?
Prestation.Length == HairLength.Long ? longhairsuffix :
Prestation.Length == HairLength.HalfLong ? halflonghairsuffix :
shorthairsuffix : null),
2017-05-12 12:15:57 +02:00
UnitaryCost =
Prestation.Gender == HairCutGenders.Women ?
2018-08-01 10:55:52 +02:00
Prestation.Length == HairLength.Long ? SelectedProfile.WomenLongCutPrice :
Prestation.Length == HairLength.HalfLong ? SelectedProfile.WomenHalfCutPrice :
SelectedProfile.WomenShortCutPrice : Prestation.Gender == HairCutGenders.Man ?
SelectedProfile.ManCutPrice : SelectedProfile.KidCutPrice
2017-05-12 12:15:57 +02:00
});
2017-06-08 11:08:33 +02:00
}
2018-08-01 10:55:52 +02:00
2017-05-12 12:15:57 +02:00
// Les techniques
switch (Prestation.Tech)
{
case HairTechnos.Color:
{
bool multicolor = Prestation.Taints.Count > 1;
string name = multicolor ? "Couleur" : "Multi-couleur";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = multicolor ? SelectedProfile.LongMultiColorPrice :
SelectedProfile.LongColorPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = multicolor ? SelectedProfile.HalfMultiColorPrice : SelectedProfile.HalfColorPrice
});
break;
default:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = multicolor ? SelectedProfile.ShortMultiColorPrice : SelectedProfile.ShortColorPrice
});
break;
}
}
break;
case HairTechnos.Balayage:
{
string name = "Balayage";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.LongBalayagePrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.HalfBalayagePrice
});
break;
default:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ShortBalayagePrice
});
break;
}
}
break;
case HairTechnos.Defris:
{
string name = "Defrisage";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.LongDefrisPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.HalfDefrisPrice
});
break;
default:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ShortDefrisPrice
});
break;
}
}
break;
case HairTechnos.Mech:
{
string name = "Mèches";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.LongMechPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.HalfMechPrice
});
break;
default:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ShortMechPrice
});
break;
}
}
break;
case HairTechnos.Permanent:
{
string name = "Mèches";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.LongPermanentPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.HalfPermanentPrice
});
break;
default:
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ShortPermanentPrice
});
break;
}
}
break;
}
// Les coiffages
switch (Prestation.Dressing)
{
case HairDressings.Brushing:
2018-08-01 10:55:52 +02:00
{
string name = "Brushing";
2017-05-12 12:15:57 +02:00
2018-08-01 10:55:52 +02:00
switch (Prestation.Gender)
{
case HairCutGenders.Women:
switch (Prestation.Length)
2017-05-12 12:15:57 +02:00
{
2018-08-01 10:55:52 +02:00
case HairLength.Long:
bill.Add(new CommandLine
{
Name = name,
Description = name + longhairsuffix,
UnitaryCost = SelectedProfile.LongBrushingPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
Name = name,
Description = name + halflonghairsuffix,
UnitaryCost = SelectedProfile.HalfBrushingPrice
});
break;
default:
bill.Add(new CommandLine
{
Name = name,
Description = name + shorthairsuffix,
UnitaryCost = SelectedProfile.ShortBrushingPrice
});
break;
}
break;
case HairCutGenders.Man:
2017-05-12 12:15:57 +02:00
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ManBrushPrice
});
2018-08-01 10:55:52 +02:00
break;
2017-05-12 12:15:57 +02:00
}
}
break;
case HairDressings.Coiffage:
// est offert
2018-08-01 10:55:52 +02:00
/* bill.Add(new CommandLine
{
Name = "Coiffage (offert)",
UnitaryCost = 0m
}); */
2017-05-12 12:15:57 +02:00
break;
case HairDressings.Folding:
{
2018-08-01 10:55:52 +02:00
string name = "Mise en plis";
switch (Prestation.Length)
{
case HairLength.Long:
2017-05-12 12:15:57 +02:00
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + longhairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.LongFoldingPrice
});
2018-08-01 10:55:52 +02:00
break;
case HairLength.HalfLong:
2017-05-12 12:15:57 +02:00
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + halflonghairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.HalfFoldingPrice
});
2018-08-01 10:55:52 +02:00
break;
default:
2017-05-12 12:15:57 +02:00
bill.Add(new CommandLine
{
2017-06-08 17:09:06 +02:00
Name = name,
Description = name + shorthairsuffix,
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.ShortFoldingPrice
});
2018-08-01 10:55:52 +02:00
break;
2017-05-12 12:15:57 +02:00
}
}
break;
2018-08-01 10:55:52 +02:00
}
2017-05-12 12:15:57 +02:00
// les soins
2018-08-01 10:55:52 +02:00
if (Prestation.Cares)
{
bill.Add(new CommandLine
{
Name = "Soins",
Description = "Soins",
UnitaryCost = SelectedProfile.CarePrice
});
2017-05-12 12:15:57 +02:00
}
return bill;
}
2018-02-03 20:17:29 +01:00
public HairCutPayementEvent CreatePaymentEvent(PaymentInfo info, IStringLocalizer localizer)
{
2018-08-01 10:55:52 +02:00
return new HairCutPayementEvent(Client.UserName, info, this, localizer);
2018-02-03 20:17:29 +01:00
}
2017-05-12 12:15:57 +02:00
public virtual BrusherProfile SelectedProfile { get; set; }
2018-08-01 10:55:52 +02:00
public HairCutQueryEvent CreateEvent(string subTopic, string reason, string sender)
{
2017-06-02 21:34:18 +02:00
2018-08-01 10:55:52 +02:00
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é]";
2017-06-02 21:34:18 +02:00
var p = Prestation;
2018-08-01 10:55:52 +02:00
string total = GetBillItems().Addition().ToString("C", CultureInfo.CurrentUICulture);
2018-08-01 03:12:08 +02:00
string strprestation = Description;
2017-06-02 21:34:18 +02:00
string bill = string.Join("\n", GetBillItems().Select(
2018-08-01 10:55:52 +02:00
l => $"{l.Name} {l.Description} {l.UnitaryCost} € " +
((l.Count != 1) ? "*" + l.Count.ToString() : "")));
2017-06-02 21:34:18 +02:00
var yaev = new HairCutQueryEvent(subTopic)
{
2018-08-01 10:55:52 +02:00
Client = new ClientProviderInfo
{
UserName = Client.UserName,
UserId = ClientId,
Avatar = Client.Avatar
},
2017-06-02 21:34:18 +02:00
Previsional = Previsional,
EventDate = EventDate,
Location = Location,
Id = Id,
ActivityCode = ActivityCode,
Reason = reason,
2018-02-25 03:33:54 +01:00
Sender = sender,
BillingCode = BillingCodes.Brush
2017-06-02 21:34:18 +02:00
};
return yaev;
}
2017-02-13 01:32:03 +01:00
}
2017-03-23 00:44:27 +01:00
}