using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Service;
using Domain;

namespace WebSite.Controllers
{
    public class SysSystemLogsController : BaseController
    {
		public ISysAuthorityManager SysAuthorityManager { get; set; }

        #region Action

        [Authorize]
        public ActionResult Index()
        {
			return View("SimonIndex");
        }

        [Authorize]
        public ActionResult LoadAllByPage(int page, int rows, string order, string sort, int? authorityId, DateTime? startDate, DateTime? endDate, string keyword)
        {
            long total = 0;
            if (string.IsNullOrEmpty(keyword)) keyword = "";
            var list = this.SysSystemLogsManager.LoadAllByPage(out total, page, rows, order, sort, authorityId, startDate, endDate, keyword, CurrentHotelID);

            var result = list.Select(r =>
            {
                var authority = SysAuthorityManager.Get(r.AuthorityID);

                return new
                {
                    r.ID,
                    r.Account,
                    Authority = authority != null ? ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName) : "",
                    r.Action,
                    r.Detail,
                    r.Result,
                    r.IP,
                    r.Time
                };
            });

            return Json(new { total = total, rows = result });
        }
        /// <summary>
        /// 删除多条数据
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
		[Authorize]
		public ActionResult Delete(IList<long> idList)
		{
			SysSystemLogsManager.Delete(idList.Cast<object>().ToList());
			return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
		}
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public ActionResult DeleteAll()
        {
            SysSystemLogsManager.DeleteAll(CurrentHotelID);
            return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("EmptySuccess") });
        }

        #endregion
    }
}
