| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 | using System;
using System.Collections.Generic;
using System.Linq;
using UnivateProperties_API.Helpers;
using UnivateProperties_API.Migrations;
using UnivateProperties_API.Model.Timeshare;
using UnivateProperties_API.Model.Users;
namespace UnivateProperties_API.Containers.Timeshare
{
    public class WeekDto : IDisplay
    {
        public WeekDto()
        {
        }
        public WeekDto(int id, string line)
        {
            Id = id;
            List<string> 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.ToString();
                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;
            AgencyId = week.AgencyId;
            Agent = $"{week.Agent?.Name} {week.Agent?.Surname}";
            AgentId = week.AgentId;
            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;
            Module = week.Module;
            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;
            CustomOwner = week.CustomOwner;
        }
        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 int? AgencyId { get; set; }
        public string Agent { get; set; }
        public int? AgentId { 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 string Bedrooms { get; set; }
        public int MaxSleep { get; set; }
        public double LevyAmount { get; set; }
        public string Module { 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; }
        public bool CustomOwner {get; set;}
    }
}
 |