using System.Linq;
using System.Web.Mvc;
using atakanozbancom;
using atakanozbancom.Models.classes;

namespace atakanozbancom.Controllers
{
    public class MainController : languageController
    {
        private readonly Context db = new Context();

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult socialicons()
        {
            var icons = db.SocialIcons
                          .OrderBy(x => x.sort_order)
                          .ThenBy(x => x.id)
                          .ToList();

            return PartialView(icons);
        }

        public PartialViewResult wallpaper()
        {
            var setting = db.SiteSettings.FirstOrDefault();
            ViewBag.WallpaperUrl = !string.IsNullOrWhiteSpace(setting?.wallpaper)
                ? setting.wallpaper
                : "/web_atakanozbancom/assets/img/wp.jpg";

            return PartialView();
        }

        [HttpGet]
        public ActionResult ChangeLanguage(string lang, string returnUrl)
        {
            new LanguageTR().SetLanguage(lang);
            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                return Redirect(returnUrl);

            return RedirectToAction("Index", "Main");
        }
    }
}