using Edu.Common.Enum;
using Edu.Model.Entity.StudyAbroad;
using Edu.Model.ViewModel.StudyAbroad;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.StudyAbroad
{
    /// <summary>
    /// 留学就业优惠信息仓储层
    /// </summary>
    public class RB_StudyaBroad_PreferentialRepository:BaseRepository<RB_StudyaBroad_Preferential>
    {
        /// <summary>
        /// 获取留学就业优惠列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_StudyaBroad_Preferential_ViewModel> GetStudyaBroadPreferentialListRepostory(RB_StudyaBroad_Preferential_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" 
SELECT * 
FROM RB_StudyaBroad_Preferential 
WHERE 1=1 ");
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_StudyaBroad_Preferential_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query == null)
            {
                return new List<RB_StudyaBroad_Preferential_ViewModel>();
            }
            else
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_StudyaBroad_Preferential_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.StudyabroadId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_StudyaBroad_Preferential_ViewModel.StudyabroadId), query.StudyabroadId);
                }
                if (!string.IsNullOrEmpty(query.QStudyabroadIds))
                {
                    builder.AppendFormat(" AND {0} IN({1}) ", nameof(RB_StudyaBroad_Preferential_ViewModel.StudyabroadId), query.QStudyabroadIds);
                }
                if (query.Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_StudyaBroad_Preferential_ViewModel.Id), query.Id);
                }
            }
            return Get<RB_StudyaBroad_Preferential_ViewModel>(builder.ToString()).ToList();
        }

        /// <summary>
        /// 根据留学就业编号删除优惠信息
        /// </summary>
        /// <param name="StudyabroadId">留学就业编号</param>
        /// <returns></returns>
        public bool DeleteStudyaBroadPreferentialRepostory(int StudyabroadId)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(" DELETE FROM RB_StudyaBroad_Preferential WHERE StudyabroadId={0} ", StudyabroadId);
            return base.Execute(builder.ToString()) > 0;
        }
    }
}
