using System; using System.Collections.Generic; using System.Linq; using UnivateProperties_API.Helpers; using UnivateProperties_API.Model.Timeshare; namespace UnivateProperties_API.Containers.Timeshare { public class WeekDto : IDisplay { public WeekDto() { } public WeekDto(int id,string line) { Id = id; List split = line.Split(",").ToList(); AgentAsRep = false; Resort = new ResortDto(split[0].Trim(), TenderWeeksHelper.GetResortName(split[0].Trim())); UnitNumber = split[1].Trim(); WeekNumber = split[2].Trim(); switch (split[8].Trim()) { case "R": Season = "Red"; break; case "W": Season = "White"; break; case "B": Season = "Blue"; break; case "1": Season = "Peak 1"; break; case "2": Season = "Peak 2"; break; case "3": Season = "Peak 3"; break; case "4": Season = "Peak 4"; break; case "5": Season = "Peak 5"; break; default: Season = split[8].Trim(); break; } var size = split[3].Trim(); if(size.Length == 3 && !size.ToLower().StartsWith('s')) { int.TryParse(size.Substring(0, 1), out int temp); Bedrooms = temp; int.TryParse(size.Substring(2, 1), out temp); MaxSleep = temp; } bool currentYear = split[9].Trim() == "Y"; string amt = split[5].Trim(); amt = amt.Replace('.', ','); if (double.TryParse(amt, out double dAmt)) LevyAmount = dAmt; DateTime tempDate = MyCommon.GetDateFromString(currentYear ? split[6].Trim() : split[13].Trim()); if(tempDate != DateTime.MinValue) { ArrivalDate = tempDate; } tempDate = MyCommon.GetDateFromString(currentYear ? split[7].Trim() : split[14].Trim()); if(tempDate != DateTime.MinValue) { DepartureDate = tempDate; } Region = new RegionDto() { RegionCode = split[24].Trim() }; IsTender = true; ReferedByAgent = false; // F-Fixed T-Timeshare (Fixed Timeshare Week) //PML - Peak / Medium / Low Felxi switch (split[25].Trim()) { case "T": case "F": WeekType = "Fixed"; break; case "P": case "M": case "L": WeekType = "Peak Flexi"; break; default: WeekType = ""; break; } } public WeekDto(TimeshareWeek week) { Id = week.Id; AgentAsRep = week.AgentAsRep; OtherResort = week.OtherResort; Agency = week.Agency?.AgencyName; Agent = $"{week.Agent?.Name} {week.Agent?.Surname}"; Owner = week.DisplayOwner; OwnerId = week.Owner.Id; UserId = week.Owner.UserId; Resort = new ResortDto(week.ResortCode, week.ResortName); Region = new RegionDto(week.Region != null ? week.Region.Id : 0, week.Region?.Code, week.Region?.Description); Season = week.Season; if(week.Status != null) { Status = new StatusDto(week.Status.Id, week.Status.Code, week.Status.Description); } Bedrooms = week.Bedrooms; MaxSleep = week.MaxSleep; UnitNumber = week.UnitNumber; WeekNumber = week.WeekNumber; LevyAmount = week.LevyAmount; CurrentYearBanked = week.CurrentYearBanked; ArrivalDate = week.ArrivalDate; DepartureDate = week.DepartureDate; SellPrice = week.SellPrice; IsTender = false; ReferedByAgent = week.ReferedByAgent; WeekType = week.WeekType.ToString(); WeekStatus = week.WeekStatus; Publish = week.Publish; PulbishedDate = week.PulbishedDate; } public int Id { get; set; } public ResortDto Resort { get; set; } public RegionDto Region { get; set; } public StatusDto Status { get; set; } public string UnitNumber { get; set; } public string WeekNumber { get; set; } public string Season { get; set; } public string Agency { get; set; } public string Agent { get; set; } public string Owner { get; set; } public int OwnerId { get; set; } public int? UserId { get; set; } public bool AgentAsRep { get; set; } public bool OtherResort { get; set; } public int Bedrooms { get; set; } public int MaxSleep { get; set; } public double LevyAmount { get; set; } public bool CurrentYearBanked { get; set; } public string BankedWith { get; set; } public DateTime ArrivalDate { get; set; } public DateTime DepartureDate { get; set; } public double SellPrice { get; set; } public bool IsTender { get; set; } public bool ReferedByAgent { get; set; } public string WeekType { get; set; } public string Display => $"{Resort.Display} ({ArrivalDate.ToShortDateString()} - {DepartureDate.ToShortDateString()})"; public string WeekUni => $"{Resort.ResortCode}-{UnitNumber}-{WeekNumber}"; public string WeekStatus { get; set; } public bool Publish { get; set; } public DateTime PulbishedDate { get; set; } } }