using CallCenter.Utility;
using CallCenterApi.Interface.Controllers.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.CutScreen
{
    public class CutScreenController : BaseController
    {
        BLL.T_Video_CutScreen bll = new BLL.T_Video_CutScreen();

        /// <summary>
        /// 开始录制 - 录屏
        /// </summary>
        /// <returns></returns>
        
        public ActionResult AddCutScreen(string callid, string cutdata)
        {
            string nowUserCode = CurrentUser.UserData.F_UserCode;
            #region 添加验证判断
            if (string.IsNullOrEmpty(callid))
                return Success("参数id错误");
            if (string.IsNullOrEmpty(cutdata))
                return Success("参数数据错误！");
            #endregion
            var model = new Model.T_Video_CutScreen();
            model.CallId = callid;          //callid
            model.VideoHtml = cutdata;      //录屏代码html
            model.CreateUserCode = nowUserCode;    // 添加人工号
            model.CreateTime = DateTime.Now;  // 添加时间
            model.IsDelete = 0;      // 删除标志：0正常，1删除
            int n = bll.Add(model);
            if (n > 0)
                return Success("录屏成功！", model);
            else
                return Error("录屏失败！");
        }

        /// <summary>
        /// 通过来电号码获取来电弹屏左侧客户信息
        /// </summary>
        /// <returns></returns>
        
        public ActionResult GetCutScreenByCallId()
        {
            string callid = HttpUtility.UrlDecode(RequestString.GetQueryString("callid"));
            if (string.IsNullOrEmpty(callid))
                return Error("参数传输失败");
            var model = bll.GetModelList(" CallId = '" + callid + "' AND IsDelete = 0 ");
            if (model.Count() > 0)
            {
                return Success("获取成功", model.Last());
            }
            else
            {
                return Success("获取成功");
            }
        }
    }
}