using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using Newtonsoft.Json;
using System.Xml;

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

            return files.ToArray();
        }

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

        // POST: api/Canalbis
        public string 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();


           // XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(data);

           // doc.Save(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + Guid.NewGuid() + ".xml"));

            
            return "ole";
        }

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

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