using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

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

        private readonly String JsonContentType = "application/json";

        [HttpGet]
        public ActionResult Load(String callback)
        {
            MobileRoot root = new MobileRoot()
            {
                status = "ok",
                results = new List<MobileElement>(),
                success = true
            };

            root.results.Add(new MobileElement
            {
                id = 1,
                testo = "Ventuno",
                valore = 21
            });

            root.results.Add(new MobileElement
            {
                id = 2,
                testo = "Venticinque",
                valore = 25
            });

            root.results.Add(new MobileElement
            {
                id = 3,
                testo = "Ventisette",
                valore = 27
            });

            if (!String.IsNullOrWhiteSpace(callback))
            {
                string s = JsonConvert.SerializeObject(root);
                return Content(callback + "(" + s + ")", JsonContentType);
            }
            else
                return Json(root, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Load(string results, string items)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create()
        {
            MobileRoot root = new MobileRoot()
            {
                status = "ok",
                results = new List<MobileElement>(),
                success = true
            };

            return Json(root, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Read()
        {
            MobileRoot root = new MobileRoot()
            {
                status = "ok",
                results = new List<MobileElement>(),
                success = true
            };

            return Json(root, JsonRequestBehavior.AllowGet);
        }

        [HttpPut]
        public ActionResult Update()
        {
            MobileRoot root = new MobileRoot()
            {
                status = "ok",
                results = new List<MobileElement>(),
                success = true
            };

            return Json(root, JsonRequestBehavior.AllowGet);
        }
    }
}
