using System.Collections.Generic;
using System.Web.Mvc;
using BLL;
using Telerik.Web.Mvc;
using ViewModels;

namespace MvcWebApp.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult GetRoles()
        {
            return View(new GridModel(GetAllRoles()));
        }

        [HttpPost]
        [GridAction]
        public ActionResult UpdateRoles([Bind(Prefix = "updated")]IEnumerable<RoleViewModel> userRoles)
        {
            var bllLibrary = new Roles();

            foreach(var role in userRoles)
                bllLibrary.UpdateRole(role);

            return View(new GridModel(GetAllRoles()));
        }

        private static IEnumerable<RoleViewModel> GetAllRoles()
        {
            var bllLibrary = new Roles();
            return bllLibrary.GetRoles();
        }
    }
}
