PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Posts.cs

#
C# | 100 lines | 82 code | 15 blank | 3 comment | 8 complexity | 205e01aaeaf950c445912f12c7c8b32a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace App_Code
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web.Script.Services;
  7. using System.Web.Services;
  8. using BlogEngine.Core;
  9. using BlogEngine.Core.Json;
  10. /// <summary>
  11. /// The comments.
  12. /// </summary>
  13. [WebService(Namespace = "http://tempuri.org/")]
  14. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  15. [ScriptService]
  16. public class Posts : WebService
  17. {
  18. [Obsolete]
  19. [WebMethod]
  20. public JsonResponse DeletePost(string id)
  21. {
  22. if (Utils.StringIsNullOrWhitespace(id))
  23. {
  24. return new JsonResponse() { Message = Resources.labels.invalidPostId };
  25. }
  26. var post = Post.GetPost(new Guid(id));
  27. if (post == null)
  28. {
  29. return new JsonResponse() { Message = Resources.labels.invalidPostId };
  30. }
  31. if (!post.CanUserDelete)
  32. {
  33. return new JsonResponse() { Message = Resources.labels.notAuthorized };
  34. }
  35. else
  36. {
  37. try
  38. {
  39. post.Delete();
  40. post.Save();
  41. return new JsonResponse() { Success = true, Message = Resources.labels.postDeleted };
  42. }
  43. catch (Exception ex)
  44. {
  45. Utils.Log(string.Format("Api.Posts.DeletePost: {0}", ex.Message));
  46. return new JsonResponse() { Message = string.Format(Resources.labels.couldNotDeletePost, ex.Message) };
  47. }
  48. }
  49. }
  50. [WebMethod]
  51. public JsonResponse DeletePage(string id)
  52. {
  53. JsonResponse response = new JsonResponse();
  54. response.Success = false;
  55. if (string.IsNullOrEmpty(id))
  56. {
  57. response.Message = Resources.labels.pageIdRequired;
  58. return response;
  59. }
  60. var page = Page.GetPage(new Guid(id));
  61. if (page == null)
  62. {
  63. return new JsonResponse() { Message = Resources.labels.invalidPageId };
  64. }
  65. if (!page.CanUserDelete)
  66. {
  67. return new JsonResponse() { Message = Resources.labels.notAuthorized };
  68. }
  69. try
  70. {
  71. page.Delete();
  72. page.Save();
  73. }
  74. catch (Exception ex)
  75. {
  76. Utils.Log(string.Format("Api.Posts.DeletePage: {0}", ex.Message));
  77. response.Message = string.Format(Resources.labels.couldNotDeletePage, ex.Message);
  78. return response;
  79. }
  80. response.Success = true;
  81. response.Message = Resources.labels.pageDeleted;
  82. return response;
  83. }
  84. }
  85. }