ModelePwaController.cs 1.2 KB

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