using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using TestMvcApp.EF;
using TestMvcApp.ViewModels;

namespace TestMvcApp.Controllers
{
    public class UserFacilityAdminController : Controller
    {

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

        #region Proposal Types

        public ActionResult ProposalTypes()
        {
            var context = new TestEntities();

            var model = (from a in context.Proposal_Types
                         where a.User_Facility_ID == "NSLS"
                         select new ProposalTypeViewModel()
                         {
                             ID = a.ID,
                             User_Facility_ID = a.User_Facility_ID,
                             Code = a.Code,
                             Description = a.Description,
                             Active = a.Active,
                             UserFacilities = (from f in context.User_Facilities
                                               select new SelectListItem
                                               {
                                                   Text = f.ID,
                                                   Value = f.ID
                                               })
                         });

            var userFacilities = (from a in context.User_Facilities
                                 select a).ToList();

            ViewData["userFacilitiesList"] = userFacilities.Select(m => new SelectListItem { Value = m.ID, Text = m.ID }).ToList();

            return View(model);
        }


        public ActionResult ProposalTypes2()
        {

            return View();
        }

        public ActionResult GetProposalTypes([DataSourceRequest]DataSourceRequest request)
        {
            using (var context = new TestEntities())
            {
                var model = (from a in context.Proposal_Types
                             where a.User_Facility_ID == "NSLS"
                             select new ProposalTypeViewModel()
                             {
                                 ID = a.ID,
                                 User_Facility_ID = a.User_Facility_ID,
                                 Code = a.Code,
                                 Description = a.Description,
                                 Active = a.Active
                             });

                DataSourceResult result = model.ToDataSourceResult(request);
                return Json(result, JsonRequestBehavior.AllowGet);
            }
        } 

        #endregion

    }
}
