using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// 党史学习教育
    /// 
    public class PartyHistoryStudyService
    {
        /// 
        /// 根据主键获取党史学习教育
        /// 
        /// 
        /// 
        public static Model.Party_PartyHistoryStudy GetPartyHistoryStudyById(string partyHistoryStudyId)
        {
            return Funs.DB.Party_PartyHistoryStudy.FirstOrDefault(e => e.PartyHistoryStudyId == partyHistoryStudyId);
        }
        /// 
        /// 添加党史学习教育
        /// 
        /// 
        public static void AddPartyHistoryStudy(Model.Party_PartyHistoryStudy partyHistoryStudy)
        {
            Model.Party_PartyHistoryStudy newPartyHistoryStudy = new Model.Party_PartyHistoryStudy
            {
                PartyHistoryStudyId = partyHistoryStudy.PartyHistoryStudyId,
                Year = partyHistoryStudy.Year,
                StudyDate = partyHistoryStudy.StudyDate,
                Speaker = partyHistoryStudy.Speaker,
                Theme = partyHistoryStudy.Theme,
                CompileMan = partyHistoryStudy.CompileMan,
                CompileDate = partyHistoryStudy.CompileDate
            };
            Funs.DB.Party_PartyHistoryStudy.InsertOnSubmit(newPartyHistoryStudy);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改党史学习教育
        /// 
        /// 
        public static void UpdatePartyHistoryStudy(Model.Party_PartyHistoryStudy partyHistoryStudy)
        {
            Model.Party_PartyHistoryStudy newPartyHistoryStudy = Funs.DB.Party_PartyHistoryStudy.FirstOrDefault(e => e.PartyHistoryStudyId == partyHistoryStudy.PartyHistoryStudyId);
            if (newPartyHistoryStudy != null)
            {
                newPartyHistoryStudy.StudyDate = partyHistoryStudy.StudyDate;
                newPartyHistoryStudy.Speaker = partyHistoryStudy.Speaker;
                newPartyHistoryStudy.Theme = partyHistoryStudy.Theme;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除党史学习教育
        /// 
        /// 
        public static void DeletePartyHistoryStudyById(string partyHistoryStudyId)
        {
            Model.Party_PartyHistoryStudy partyHistoryStudy = Funs.DB.Party_PartyHistoryStudy.FirstOrDefault(e => e.PartyHistoryStudyId == partyHistoryStudyId);
            if (partyHistoryStudy != null)
            {
                CommonService.DeleteAttachFileById(partyHistoryStudyId);
                Funs.DB.Party_PartyHistoryStudy.DeleteOnSubmit(partyHistoryStudy);
                Funs.DB.SubmitChanges();
            }
        }
    }
}