using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RMYY_CallCenter_Api.Controllers.System
{
    //工作日管理
    public class WorkOffDaysController : BaseController
    {
        Bll.T_Sys_WorkOffDays dBLL = new Bll.T_Sys_WorkOffDays();
        //获取休息日列表
        public ActionResult GetList(string date)
        {
            string sql = " and DATEDIFF(MONTH,GETDATE(),f_offdate) in (-1,0,1) ";
            if (!string.IsNullOrEmpty(date))
                sql = " and DATEDIFF(MONTH,'"+ date + "',f_offdate) in (-1,0,1) ";
            List<Model.T_Sys_WorkOffDays> wodlist = dBLL.GetModelList(" F_OffState=0 " + sql + " order by F_OffDate");
            var obj = wodlist.Select(wol => new
            {
                date = wol.F_OffDate.Value.ToString("yyyy-MM-dd"),
            });
            return Success("获取成功", obj);
        }

        /// <summary>
        /// 设置或取消休息日
        /// </summary>
        /// <param name="offdate">日期</param>
        /// <param name="type">0，设为休息日；1，取消休息日</param>
        /// <returns></returns>
        public ActionResult setOfforOn(string offdate, int type)
        {
            if (string.IsNullOrWhiteSpace(offdate))
                return Error("参数错误");

            Model.T_Sys_WorkOffDays dModel = dBLL.GetModel(offdate);
            if (dModel == null)
            {
                return Error("设置的日期有误，请联系管理员");
            }
            dModel.F_OffDate = Convert.ToDateTime(offdate);
            dModel.F_OffState = type;
            dModel.F_DeleteBy = User.F_UserCode;
            dModel.F_DeleteOn = DateTime.Now;

            var res = dBLL.UpdateState(dModel);
            if (res)
            {
                return Success("设置成功");
            }
            else
            {
                return Error("设置失败");
            }
        }
    }
}