PageRenderTime 33ms CodeModel.GetById 16ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

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

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