using PageAdmin.Common;
using PageAdmin.Web.Filter;
using PageAdmin.Utils.ORM;
using PageAdmin.Utils;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.E.Controllers
{
    public class UpdateListXuhaoController: BaseController
    {
        DataBaseContext _DbContext;

        public UpdateListXuhaoController()
        {
            _DbContext = DbHelper.DbContext();
        }

        [AjaxOnly]
        [HttpPost]
        public JsonResult Index(FormCollection form)
        {
            string table = StringHelper.Format<string>(form["table"]);
            string ids = StringHelper.Format<string>(form["ids"]);
            string values = StringHelper.Format<string>(form["values"]);
            string field = StringHelper.Format<string>(form["field"]);
            string[] arrIds = StringHelper.Unique<int>(ids).Split(',');
            string[] arrValues = StringHelper.Unique<int>(values).Split(',');
            if(arrIds.Length!= arrValues.Length) { return null; }
            if (!StringHelper.IsStr(table) || !StringHelper.IsStr(field)) { return null; }
            for (int i=0;i< arrIds.Length;i++)
            {
                _DbContext.Update(table, field, arrValues[i],"id="+ arrIds[i]);
            }
            CacheHelper.RemoveDbCache(table); //改变序号后更新缓存
            return null;
        }

    }
}
