Trip.cs
2,423 bytes
| 1 | using System.ComponentModel.DataAnnotations; |
|---|---|
| 2 | using App.Domain.Identity; |
| 3 | using Base.Domain; |
| 4 | |
| 5 | namespace App.Domain; |
| 6 | |
| 7 | public class Trip : BaseEntity, IValidatableObject |
| 8 | { |
| 9 | [MaxLength(200, ErrorMessageResourceType = typeof(App.Resources.Common), ErrorMessageResourceName = "ErrorMaxLength")] |
| 10 | [Display(Name = nameof(Name), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 11 | public string Name { get; set; } = default!; |
| 12 | |
| 13 | [Display(Name = nameof(Description), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 14 | public string? Description { get; set; } |
| 15 | |
| 16 | [MaxLength(200, ErrorMessageResourceType = typeof(App.Resources.Common), ErrorMessageResourceName = "ErrorMaxLength")] |
| 17 | [Display(Name = nameof(Destination), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 18 | public string? Destination { get; set; } |
| 19 | |
| 20 | [Display(Name = nameof(StartDate), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 21 | public DateTime? StartDate { get; set; } |
| 22 | |
| 23 | [Display(Name = nameof(EndDate), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 24 | public DateTime? EndDate { get; set; } |
| 25 | |
| 26 | [Display(Name = nameof(Status), ResourceType = typeof(App.Resources.Domain.Trip))] |
| 27 | public ETripStatus Status { get; set; } = ETripStatus.Active; |
| 28 | |
| 29 | [Display(Name = "DefaultCurrency", ResourceType = typeof(App.Resources.Domain.Trip))] |
| 30 | public Guid DefaultCurrencyId { get; set; } |
| 31 | public Currency? DefaultCurrency { get; set; } |
| 32 | |
| 33 | [Display(Name = "CreatedBy", ResourceType = typeof(App.Resources.Domain.Trip))] |
| 34 | public Guid CreatedById { get; set; } |
| 35 | public AppUser? CreatedBy { get; set; } |
| 36 | |
| 37 | public ICollection<TripParticipant>? Participants { get; set; } |
| 38 | public ICollection<Expense>? Expenses { get; set; } |
| 39 | public ICollection<BudgetCategory>? BudgetCategories { get; set; } |
| 40 | public ICollection<TripWishlistItem>? WishlistItems { get; set; } |
| 41 | public ICollection<TripPoll>? Polls { get; set; } |
| 42 | public ICollection<TripInvitation>? Invitations { get; set; } |
| 43 | public ICollection<SettlementPlan>? SettlementPlans { get; set; } |
| 44 | |
| 45 | public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| 46 | { |
| 47 | if (StartDate.HasValue && EndDate.HasValue && EndDate.Value < StartDate.Value) |
| 48 | { |
| 49 | yield return new ValidationResult( |
| 50 | "End date must be on or after start date.", |
| 51 | new[] { nameof(EndDate) }); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |