using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PersonalFinance.Entity;
namespace PersonalFinance
{
public enum Frequency { None, Once, Daily, Weekly, Monthly, Quarterly, Biannually, Yearly }
///
/// Scheduling of payments
/// - repeated/regular
/// - temporary repeated
/// - plannig - one times
///
public class ScheduledItem
{
public ScheduledItem()
{
LastUse = DateTime.Now.AddDays(-1);
}
///
/// Unique scheduling identification number (Primary key)
///
[Key]
public int ScheduledItemId { get; set; }
///
/// Link to payment (Foreign key)
///
private Payment payment;
public Payment Payment
{
get { return payment; }
set
{
if (value != null)
{
payment = value;
}
else
{
throw new ArgumentNullException("Payment cannot be null.");
//throw new NullReferenceException("Payment");
}
}
}
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 override string ToString()
{
if(Until == null){
return string.Format("ScheduledItem {0}: {1} for Payment {2} last at {3}", ScheduledItemId, Frequency, Payment.PaymentId, LastUse.ToString("dd/MM/yyyy"));
}else {
return string.Format("ScheduledItem {0}: {1} until {2} for Payment {3} last at {4}", ScheduledItemId, Frequency, Until, Payment.PaymentId, LastUse.ToString("dd/MM/yyyy"));
}
}
}
}