MobiparcController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. using System.IO;
  8. using Newtonsoft.Json;
  9. using System.Xml;
  10. namespace mobiparc.Controllers
  11. {
  12. public class MobiparcController : ApiController
  13. {
  14. // GET: api/Mobiparc
  15. public IEnumerable<string> Get()
  16. {
  17. var files = Directory.EnumerateFiles(System.Web.HttpContext.Current.Server.MapPath(@"~/data/"));
  18. return files.ToArray();
  19. }
  20. // GET: api/Mobiparc/5
  21. public string Get(string name)
  22. {
  23. return File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + name + ".json"));
  24. }
  25. // POST: api/Mobiparc
  26. public int Post([FromBody]string value)
  27. {
  28. var data = System.Web.HttpContext.Current.Request["data"];
  29. var f= File.CreateText(System.Web.HttpContext.Current.Server.MapPath(@"~/data/" + Guid.NewGuid() +".json"));
  30. f.Write(data);
  31. f.Close();
  32. return 0;
  33. }
  34. // PUT: api/Mobiparc/5
  35. public void Put(int id, [FromBody]string value)
  36. {
  37. }
  38. // DELETE: api/Mobiparc/5
  39. public void Delete(int id)
  40. {
  41. }
  42. }
  43. }