using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// “两优一先”评选表
    /// 
    public class TwoOneGoodSelectionService
    {
        /// 
        /// 根据主键获取“两优一先”评选表
        /// 
        /// 
        /// 
        public static Model.Party_TwoOneGoodSelection GetTwoOneGoodSelectionById(string twoOneGoodSelectionId)
        {
            return Funs.DB.Party_TwoOneGoodSelection.FirstOrDefault(e => e.TwoOneGoodSelectionId == twoOneGoodSelectionId);
        }
        /// 
        /// 根据类别获取字符串
        /// 
        /// 
        /// 
        public static string GetSelectionType(string selectionType)
        {
            string type = string.Empty;
            if (selectionType == "1")
            {
                type = "优秀党员";
            }
            else if (selectionType == "2")
            {
                type = "优秀党务工作者";
            }
            else if (selectionType == "3")
            {
                type = "先进基层党支部";
            }
            return type;
        }
        /// 
        /// 根据主键获取当选人/党支部
        /// 
        /// 
        /// 
        public static string GetName(string twoOneGoodSelectionId)
        {
            string name = string.Empty;
            Model.Party_TwoOneGoodSelection twoOneGoodSelection = Funs.DB.Party_TwoOneGoodSelection.FirstOrDefault(x=>x.TwoOneGoodSelectionId== twoOneGoodSelectionId);
            if (twoOneGoodSelection != null)
            {
                if (twoOneGoodSelection.SelectionType == "3")
                {
                    name = twoOneGoodSelection.PartyBranch;
                }
                else
                {
                    Model.Party_Partyer partyer = Funs.DB.Party_Partyer.FirstOrDefault(x=>x.PartyerId==twoOneGoodSelection.PartyerId);
                    if (partyer != null)
                    {
                        name = partyer.Name;
                    }
                }
            }
            return name;
        }
        /// 
        /// 添加“两优一先”评选表
        /// 
        /// 
        public static void AddTwoOneGoodSelection(Model.Party_TwoOneGoodSelection twoOneGoodSelection)
        {
            Model.Party_TwoOneGoodSelection newTwoOneGoodSelection = new Model.Party_TwoOneGoodSelection
            {
                TwoOneGoodSelectionId = twoOneGoodSelection.TwoOneGoodSelectionId,
                Year = twoOneGoodSelection.Year,
                SelectionType = twoOneGoodSelection.SelectionType,
                PartyerId = twoOneGoodSelection.PartyerId,
                PartyBranch = twoOneGoodSelection.PartyBranch,
                CompileMan = twoOneGoodSelection.CompileMan,
                CompileDate = twoOneGoodSelection.CompileDate
            };
            Funs.DB.Party_TwoOneGoodSelection.InsertOnSubmit(newTwoOneGoodSelection);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改“两优一先”评选表
        /// 
        /// 
        public static void UpdateTwoOneGoodSelection(Model.Party_TwoOneGoodSelection twoOneGoodSelection)
        {
            Model.Party_TwoOneGoodSelection newTwoOneGoodSelection = Funs.DB.Party_TwoOneGoodSelection.FirstOrDefault(e => e.TwoOneGoodSelectionId == twoOneGoodSelection.TwoOneGoodSelectionId);
            if (newTwoOneGoodSelection != null)
            {
                newTwoOneGoodSelection.SelectionType = twoOneGoodSelection.SelectionType;
                newTwoOneGoodSelection.PartyerId = twoOneGoodSelection.PartyerId;
                newTwoOneGoodSelection.PartyBranch = twoOneGoodSelection.PartyBranch;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除“两优一先”评选表
        /// 
        /// 
        public static void DeleteTwoOneGoodSelectionById(string twoOneGoodSelectionId)
        {
            Model.Party_TwoOneGoodSelection twoOneGoodSelection = Funs.DB.Party_TwoOneGoodSelection.FirstOrDefault(e => e.TwoOneGoodSelectionId == twoOneGoodSelectionId);
            if (twoOneGoodSelection != null)
            {
                CommonService.DeleteAttachFileById(twoOneGoodSelectionId);
                Funs.DB.Party_TwoOneGoodSelection.DeleteOnSubmit(twoOneGoodSelection);
                Funs.DB.SubmitChanges();
            }
        }
    }
}