using System;
using System.Collections.Generic;
using Library;
using System.Linq;
using MySystem.Models.Main;

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

        #region 获取单个字段
        public Users Get(int Id)
        {
            WebCMSEntities db = new WebCMSEntities();
            Users order = db.Users.FirstOrDefault(m => m.Id == Id);
            if (order != null)
            {
            }
            db.Dispose();
            return order;
        }
        //个人新增创客
        public int GetNewUserCount(int UserId, string TradeMonthOrDate = "")
        {
            int count = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(string.IsNullOrEmpty(TradeMonthOrDate))
            {
                bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.SeoTitle == "self");
                if (check)
                {
                    count = db.PullnewSummary.Where(m => m.UserId == UserId && m.SeoTitle == "self").Sum(m => m.RecUserAuthNum);
                }
            }
            else
            {
                if(TradeMonthOrDate.Length == 8)
                {
                    bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.StatDate == TradeMonthOrDate && m.SeoTitle == "self");
                    if (check)
                    {
                        count = db.PullnewSummary.Where(m => m.UserId == UserId && m.StatDate == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.RecUserAuthNum);
                    }
                }
                else
                {
                    bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.StatMonth == TradeMonthOrDate && m.SeoTitle == "self");
                    if (check)
                    {
                        count = db.PullnewSummary.Where(m => m.UserId == UserId && m.StatMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.RecUserAuthNum);
                    }
                }
            }
            db.Dispose();
            return count;
        }
        //团队新增创客
        public int GetTeamNewUserCount(int UserId, string TradeMonthOrDate = "")
        {
            int count = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(string.IsNullOrEmpty(TradeMonthOrDate))
            {
                bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.SeoTitle == "team");
                if (check)
                {
                    count = db.PullnewSummary.Where(m => m.UserId == UserId && m.SeoTitle == "team").Sum(m => m.RecUserAuthNum);
                }
            }
            else
            {
                if(TradeMonthOrDate.Length == 8)
                {
                    bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.StatDate == TradeMonthOrDate && m.SeoTitle == "team");
                    if (check)
                    {
                        count = db.PullnewSummary.Where(m => m.UserId == UserId && m.StatDate == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.RecUserAuthNum);
                    }
                }
                else
                {
                    bool check = db.PullnewSummary.Any(m => m.UserId == UserId && m.StatMonth == TradeMonthOrDate && m.SeoTitle == "team");
                    if (check)
                    {
                        count = db.PullnewSummary.Where(m => m.UserId == UserId && m.StatMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.RecUserAuthNum);
                    }
                }
            }
            db.Dispose();
            return count;
        }
        #endregion

    }
}
