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

414 lines
17 KiB
C#

8 years ago
using System;
7 years ago
using System.Collections.Generic;
8 years ago
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models.Billing;
8 years ago
using Yavsc.Models.Relationship;
using Yavsc.Billing;
using System.Globalization;
using Yavsc.Helpers;
using System.Linq;
using Microsoft.Extensions.Localization;
using Yavsc.ViewModels.PayPal;
using Yavsc.Models.HairCut;
6 years ago
using Yavsc.Abstract.Identity;
8 years ago
namespace Yavsc.Models.Haircut
{
8 years ago
public class HairCutQuery : NominativeServiceCommand
8 years ago
{
7 years ago
// Bill description
7 years ago
public override string GetDescription()
{
7 years ago
string type = ResourcesHelpers.GlobalLocalizer[this.GetType().Name];
string gender = ResourcesHelpers.GlobalLocalizer[this.Prestation.Gender.ToString()];
7 years ago
7 years ago
return $"{type} ({gender})";
7 years ago
}
7 years ago
8 years ago
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
override public long Id { get; set; }
8 years ago
[Required]
public long PrestationId { get; set; }
7 years ago
[ForeignKey("PrestationId"), Required, Display(Name = "Préstation")]
public virtual HairPrestation Prestation { get; set; }
8 years ago
[ForeignKey("LocationId")]
7 years ago
[Display(Name = "Lieu du rendez-vous")]
8 years ago
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Pas de lieu spécifié]")]
7 years ago
public virtual Location Location { get; set; }
8 years ago
7 years ago
[Display(Name = "Date et heure")]
[DisplayFormat(NullDisplayText = "[Pas de date ni heure]", ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? EventDate
8 years ago
{
get;
set;
}
public long? LocationId
{
get;
set;
}
8 years ago
7 years ago
[Display(Name = "Informations complémentaires"),
8 years ago
StringLengthAttribute(512)]
8 years ago
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[pas d'informations complémentaires]")]
8 years ago
public string AdditionalInfo { get; set; }
7 years ago
public override List<IBillItem> GetBillItems()
{
string longhairsuffix = " (cheveux longs)";
string halflonghairsuffix = " (cheveux mi-longs)";
string shorthairsuffix = " (cheveux courts)";
List<IBillItem> bill = new List<IBillItem>();
7 years ago
if (this.Prestation==null) throw new InvalidOperationException("Prestation property is null");
if (this.SelectedProfile==null) throw new InvalidOperationException("SelectedProfile property is null");
7 years ago
// Le shampoing
if (this.Prestation.Shampoo)
7 years ago
bill.Add(new CommandLine { Name = "Shampoing", Description="Shampoing", UnitaryCost = SelectedProfile.ShampooPrice });
7 years ago
// la coupe
if (Prestation.Cut) {
bill.Add(new CommandLine
7 years ago
{
7 years ago
Name = "Coupe",
7 years ago
Description = $"Coupe "+
7 years ago
ResourcesHelpers.GlobalLocalizer[Prestation.Gender.ToString()]+ " "+
(Prestation.Gender == HairCutGenders.Women ?
Prestation.Length == HairLength.Long ? longhairsuffix :
Prestation.Length == HairLength.HalfLong ? halflonghairsuffix :
shorthairsuffix: null),
7 years ago
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
});
}
7 years ago
// 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
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = multicolor ? SelectedProfile.LongMultiColorPrice :
SelectedProfile.LongColorPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = multicolor ? SelectedProfile.HalfMultiColorPrice : SelectedProfile.HalfColorPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name = name + shorthairsuffix,
7 years ago
UnitaryCost = multicolor ? SelectedProfile.ShortMultiColorPrice : SelectedProfile.ShortColorPrice
});
break;
}
}
break;
case HairTechnos.Balayage:
{
string name = "Balayage";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongBalayagePrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfBalayagePrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ShortBalayagePrice
});
break;
}
}
break;
case HairTechnos.Defris:
{
string name = "Defrisage";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongDefrisPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfDefrisPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ShortDefrisPrice
});
break;
}
}
break;
case HairTechnos.Mech:
{
string name = "Mèches";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongMechPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfMechPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ShortMechPrice
});
break;
}
}
break;
case HairTechnos.Permanent:
{
string name = "Mèches";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongPermanentPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfPermanentPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
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
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongBrushingPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfBrushingPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ShortBrushingPrice
});
break;
}
break;
case HairCutGenders.Man:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ManBrushPrice
});
break;
}
}
break;
case HairDressings.Coiffage:
// est offert
/* bill.Add(new CommandLine
7 years ago
{
Name = "Coiffage (offert)",
UnitaryCost = 0m
}); */
7 years ago
break;
case HairDressings.Folding:
{
string name = "Mise en plis";
switch (Prestation.Length)
{
case HairLength.Long:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + longhairsuffix,
7 years ago
UnitaryCost = SelectedProfile.LongFoldingPrice
});
break;
case HairLength.HalfLong:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + halflonghairsuffix,
7 years ago
UnitaryCost = SelectedProfile.HalfFoldingPrice
});
break;
default:
bill.Add(new CommandLine
{
7 years ago
Name = name,
Description = name + shorthairsuffix,
7 years ago
UnitaryCost = SelectedProfile.ShortFoldingPrice
});
break;
}
}
break;
}
// les soins
if (Prestation.Cares) {
bill.Add(new CommandLine { Name = "Soins",
7 years ago
Description = "Soins",
7 years ago
UnitaryCost = SelectedProfile.CarePrice });
}
return bill;
}
public HairCutPayementEvent CreatePaymentEvent(PaymentInfo info, IStringLocalizer localizer)
{
return new HairCutPayementEvent(Client.UserName,info,this, localizer);
}
7 years ago
public virtual BrusherProfile SelectedProfile { get; set; }
public HairCutQueryEvent CreateEvent(string subTopic, string reason, string sender) {
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,
7 years ago
Sender = sender,
BillingCode = BillingCodes.Brush
};
return yaev;
}
8 years ago
}
}