using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using PersonalFinance.Entity; using System.ComponentModel.DataAnnotations.Schema; namespace PersonalFinance { /// /// Scheduling of payments /// - repeated/regular /// - temporary repeated /// - plannig - one times /// public class ScheduledPayment : BasePayment { public ScheduledPayment() { LastUse = DateTime.Now.AddDays(-1); Group = PaymentGroup.Personal; Price = 0; Currency = PaymentCurrency.CZK; } /// /// Unique scheduling identification number (Primary key) /// [Key] public int ScheduledItemId { get; set; } private Frequency freq; /// /// Frequency of payment /// public Frequency Frequency { get { return freq; } set { if (Frequency.IsDefined(typeof(Frequency), value)){ this.freq = value; } else { throw new ArgumentOutOfRangeException("Value is not defined enum from Frequency!"); } } } [Range(typeof(DateTime), "1.1.1950", "31.12.2100")] private DateTime? until; /// /// Specifies how long to be scheduled /// If Frequency if 'Once' date should not be 'null' /// /// public DateTime? Until { get { return until; } set { if (Frequency == Frequency.Once && value == null) { throw new ArgumentNullException("Until null DateTime cannot be combinate with Frequency.Once."); } else { until = value; } } } /// /// Last use cheduled payment in paiments current user - for runnig after long time /// [Range(typeof(DateTime), "1.1.1950", "31.12.2100")] private DateTime lastUse; public DateTime LastUse { get { return lastUse; } set { if (value == null) { throw new ArgumentNullException("LastUse cannot be null."); } else { lastUse = value; } } } public Payment ToPayment() { return new Payment(){ Currency = this.Currency, Date = DateTime.Now, Price = this.Price, Purpose = this.Purpose, Group = this.Group, Paid = false, Note = this.Note, User = this.User }; } public override string ToString() { if(Until == null){ return string.Format("ScheduledItem {0}: {1} last at {2}", ScheduledItemId, Frequency, LastUse.ToString("dd/MM/yyyy")); }else { return string.Format("ScheduledItem {0}: {1} until {2} last at {3}", ScheduledItemId, Frequency, Until, LastUse.ToString("dd/MM/yyyy")); } } } }