yavsc/Yavsc/Models/HairCut/HairCutQuery.cs

405 lines
17 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 Yavsc.Models.Messaging;
using System.Linq;
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
2017-05-30 23:42:04 +02:00
public override string GetDescription()
2017-05-05 23:37:07 +02:00
{
2017-06-08 17:09:06 +02:00
string type = Startup.GlobalLocalizer[this.GetType().Name];
string gender = Startup.GlobalLocalizer[this.Prestation.Gender.ToString()];
2017-05-30 23:42:04 +02:00
return $"{type} ({gender})";
2017-05-12 12:15:57 +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>();
2017-05-12 16:29:47 +02:00
#if DEBUG
if (this.Prestation==null) throw new InvalidOperationException("Prestation");
if (this.SelectedProfile==null) throw new InvalidOperationException("SelectedProfile");
#endif
2017-05-12 12:15:57 +02:00
// Le shampoing
if (this.Prestation.Shampoo)
2017-06-08 17:09:06 +02:00
bill.Add(new CommandLine { Name = "Shampoing", Description="Shampoing", UnitaryCost = SelectedProfile.ShampooPrice });
2017-05-12 12:15:57 +02:00
// la coupe
2017-06-08 11:08:33 +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",
2017-06-08 11:08:33 +02:00
Description = $"Coupe "+Startup.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 ?
Prestation.Length == HairLength.Long ? SelectedProfile.WomenLongCutPrice :
Prestation.Length == HairLength.HalfLong ? SelectedProfile.WomenHalfCutPrice :
SelectedProfile.WomenShortCutPrice : Prestation.Gender == HairCutGenders.Man ?
SelectedProfile.ManCutPrice : SelectedProfile.KidCutPrice
});
2017-06-08 11:08:33 +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:
{
string name = "Brushing";
switch (Prestation.Gender)
{
case HairCutGenders.Women:
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.LongBrushingPrice
});
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.HalfBrushingPrice
});
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.ShortBrushingPrice
});
break;
}
break;
case HairCutGenders.Man:
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
});
break;
}
}
break;
case HairDressings.Coiffage:
// est offert
2017-05-12 16:29:47 +02:00
/* bill.Add(new CommandLine
2017-05-12 12:15:57 +02:00
{
Name = "Coiffage (offert)",
UnitaryCost = 0m
2017-05-12 16:29:47 +02:00
}); */
2017-05-12 12:15:57 +02:00
break;
case HairDressings.Folding:
{
string name = "Mise en plis";
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.LongFoldingPrice
});
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.HalfFoldingPrice
});
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.ShortFoldingPrice
});
break;
}
}
break;
}
// les soins
if (Prestation.Cares) {
bill.Add(new CommandLine { Name = "Soins",
2017-06-08 17:09:06 +02:00
Description = "Soins",
2017-05-12 12:15:57 +02:00
UnitaryCost = SelectedProfile.CarePrice });
}
return bill;
}
public virtual BrusherProfile SelectedProfile { get; set; }
2017-06-02 21:34:18 +02:00
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;
}
2017-02-13 01:32:03 +01:00
}
2017-03-23 00:44:27 +01:00
}