using System;
using System.Collections.Generic;
using Library;
using System.Linq;
using MySystem.MainModels;

namespace MySystem
{
    public class UserAmountSummary
    {
        public readonly static UserAmountSummary Instance = new UserAmountSummary();
        public UserAmountSummary()
        { }

        public decimal GetTrade(int UserId, string kind = "self")
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            bool check = db.UserAmountSummary.Any(m => m.UserId == UserId && m.SeoTitle == kind);
            if (check)
            {
                if (kind == "self")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
                else if (kind == "team")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
            }
            db.Dispose();
            return amt;
        }
        public decimal GetTradeByMonth(int UserId, string TradeMonth, string kind = "self")
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            bool check = db.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth &&m.SeoTitle == kind);
            if (check)
            {
                if (kind == "self")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth &&m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
                else if (kind == "team")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth &&m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
            }
            db.Dispose();
            return amt;
        }

        public decimal GetTradeByDate(int UserId, string TradeDate, string kind = "self")
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            bool check = db.UserAmountSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeDate &&m.SeoTitle == kind);
            if (check)
            {
                if (kind == "self")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate &&m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
                else if (kind == "team")
                {
                    amt = db.UserAmountSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate &&m.SeoTitle == kind).Sum(m => m.TotalAmount);
                }
            }
            db.Dispose();
            return amt;
        }
    }
}
