using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonalFinance
{
public enum PaymentGroup { Family, Personal, Private }
public enum PaymentCurrency { CZK, EUR, USD }
///
/// Payment for goods or services in family (similar to invoices in corporation)
///
public class Payment
{
public Payment() { }
public Payment(User user)
{
Paid = false;
Group = PaymentGroup.Personal;
Price = 0;
Currency = PaymentCurrency.CZK;
User = user;
}
///
/// Unique payment identification number (Primary key)
///
[Key]
public int PaymentId { get; set; }
private int price;
///
/// Price of payment - must be positive number
///
public int Price {
get { return price; }
set
{
if (value >= 0) { price = value; }
else { throw new ArgumentOutOfRangeException("Price cannot be negative."); }
}
}
private PaymentCurrency curr;
///
/// Payment currency
///
public PaymentCurrency Currency {
get { return curr; }
set
{
if (PaymentCurrency.IsDefined(typeof(PaymentCurrency), value)) { this.curr = value; }
else { throw new ArgumentOutOfRangeException("Value is not defined enum from PaymentCurrency!"); }
}
}
///
/// Price of payment - must be positive number
///
[Range(typeof(DateTime), "1.1.1950", "31.12.2100")]
public DateTime Date { get; set; }
private User user;
public User User {
get { return user; }
set
{
if (value != null)
{
user = value;
}
else
{
throw new ArgumentNullException("User cannot be null.");
}
}
}
///
/// Purpose of payment
///
public string Purpose { get; set; }
///
/// Note of payment
///
public string Note { get; set; }
private PaymentGroup group;
///
/// Type of payment (defines the visibility)
///
public PaymentGroup Group {
get { return group; }
set
{
if (PaymentGroup.IsDefined(typeof(PaymentGroup), value)) { this.group = value; }
else { throw new ArgumentOutOfRangeException("Value is not defined enum from PaymentGroup!"); }
}
}
///
/// Tags of payment for better search and ordering
///
public List Tags { get; set; }
///
/// Payment status (nesecary for scheduling)
///
public bool Paid { get; set; }
public bool ExistTag(string tagName)
{
return Tags.Exists(x => x == tagName.ToLower());
}
public override string ToString()
{
string str = "Payment {0}: {1} {2} {3} for {4} {5}";
if(Note != null){
str += " has Note";
}
return string.Format(str,
PaymentId, Price, Currency, Group, Purpose, Paid ? "zaplaceno" : "nezaplaceno");
}
}
}