using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Domain;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Service;

namespace WebSite.Controllers
{
    public class HostModalRecordController : BaseController
    {
		public IHostModalRecordManager HostModalRecordManager { get; set; }

        public ActionResult Index()
        {
            return View();
        }

		public ActionResult LoadRoomNumbers()
		{
			IList<object> result = new List<object>();

			IList<string> roomNumbers = HostModalRecordManager.LoadRoomNumbers(CurrentHotelID);

			foreach (string roomNumber in roomNumbers)
			{
				result.Add(new { Value = roomNumber, Name = roomNumber });
			}

			return Json(result, JsonRequestBehavior.AllowGet);
		}

        public ActionResult LoadModals(string roomNumber)
        {
            var table = HostModalRecordManager.LoadModals(roomNumber, CurrentHotelID);
            var list = new List<object>();
            foreach (DataRow row in table.Rows)
            {
                list.Add(new
                {
                    RoomType = row["RoomType"],
                    ModalAddress = row["ModalAddress"],
                    Outlet = row["Outlet"],
                    Name = ReturnNameByLanguage(row["Name"].ToString(), row["EnglishName"].ToString(), row["TWName"].ToString())// (Language == Language.CN) ? row["Name"] : row["EnglishName"]
                });
            }
            return Json(new { total = list.Count, rows = list });
        }
    }
}
