using System.Web.Mvc;
using AutoMapper;
using Qusion.Cms.Users.Core;
using Qusion.Cms.Users.Domain;
using Qusion.WebApp.Areas.Qusion.Filters;
using Qusion.WebApp.Areas.Qusion.Models;
using Qusion.WebApp.Areas.Qusion.Models.Users;
using Qusion.Framework.Configuration;
using System.Web;
using System.Collections.Generic;
using Qusion.Cms.Media.Images;
using Qusion.Cms.Media.Core;

namespace Qusion.WebApp.Areas.Qusion.Controllers
{
    [QusionAuthorize(LoginPage = "/qusion/account/login")]
    public class AppController : Controller
    {
        private readonly UserService _userService;
        private readonly ImageService _imageService;

        public AppController(UserService userService, ImageService imageService)
        {
            _userService = userService;
            _imageService = imageService;
        }

        //
        // GET: /Qusion/App/
        public ActionResult Index()
        {
            var user = _userService.Get(User.Identity.Name);
            var model = Mapper.Map<User, UserModel>(user);
            return View(new AppModel
            {
                User = model
            });

          }
     
        [HttpGet]
        public JsonResult SetCulture(string culture)//HERE value is ALLWAYS NULL.. :(
        {
            ConfigHelper.LocalizationSection.Cultures.DefaultCulture = culture;
            return Json(culture, JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public ActionResult Json()
        {
            IEnumerable<ImageItem> images = _imageService.GetAll();
            return Json(images, JsonRequestBehavior.AllowGet);
        }

    }
}