using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.IO;

namespace mobiparc.Controllers
{
    public class MobiparcController : ApiController
    {
        // GET: api/mobiparc
        public IEnumerable<string> Get()
        {
            
           var files = Directory.EnumerateFiles(System.Web.HttpContext.Current.Server.MapPath(@"~/data/"));

            return files.ToArray();
        }

        // GET: api/mobiparc/5
        public string Get(string name)
        {
            return File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + name + ".json"));
        }

        // POST: api/mobiparc
        public int Post([FromBody]string value)
        {
           var data =  System.Web.HttpContext.Current.Request["data"];
           var f= File.CreateText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + Guid.NewGuid() +".json"));
            f.Write(data);
            f.Close();
            return 0;
        }

        // PUT: api/mobiparc/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/mobiparc/5
        public void Delete(int id)
        {
        }
    }
}
