Ejemplo n.º 1
0
        public async Task <Response <PostList> > BrowsePostsAsync(PostOptions options = null)
        {
            var requestUri = new StringBuilder();

            requestUri.Append($"/ghost/api/v3/content/posts/?key={_apiKey}");

            if (options != null)
            {
                requestUri.Append(options.Include != Include.None
                    ? $"&include={options.Include.GetDescriptions()}"
                    : string.Empty);
                requestUri.Append(options.Format != Format.None
                    ? $"&formats={options.Format.GetDescriptions()}"
                    : string.Empty);
                requestUri.Append(options.Fields != PostFields.None
                    ? $"&fields={options.Fields.GetDescriptions()}"
                    : string.Empty);

                requestUri.Append(options.Page != string.Empty
                    ? $"&page={options.Page}"
                    : string.Empty);
                requestUri.Append(options.Limit != string.Empty ? $"&limit={options.Limit}" : string.Empty);
                requestUri.Append(options.Filter != string.Empty ? $"&filter={options.Filter}" : string.Empty);
                requestUri.Append(options.Order != string.Empty ? $"&order={options.Order}" : string.Empty);
            }

            return(await GetRequestAsync <PostList>(requestUri));
        }
Ejemplo n.º 2
0
        public static int getUpdatesType(string userId, string FriendId)
        {
            int UpdateType = 0;
            MongoCollection <PostOptions> objCollection3 = db.GetCollection <PostOptions>("c_PostOption");
            var querytype = Query.And(
                Query.EQ("UserId", ObjectId.Parse(userId)),
                Query.EQ("FriendId", ObjectId.Parse(FriendId))
                );

            var types = objCollection3.Find(querytype);

            try
            {
                if (types.First() != null)
                {
                    PostOptions item = types.First();
                    UpdateType = item.UpdatesType;
                }
            }
            catch (Exception ex)
            {
                //PostOptions item = types.First();
                //UpdateType = item.UpdatesType;
            }
            return(UpdateType);

            //   return WallDAL.getUpdatesType(userId, FriendId);
        }
Ejemplo n.º 3
0
 public bool DeletePost([FromBody] PostOptions postOptions)
 {
     if (postOptions != null)
     {
         return(_postservices.DeletePost(postOptions.PostId));
     }
     return(false);
 }
Ejemplo n.º 4
0
        public IActionResult UpdatePost([FromBody] PostOptions postOptions)
        {
            var result = _postservices.UpdatePost(postOptions);

            if (!result.Success)
            {
                return(StatusCode((int)result.ErrorCode,
                                  result.ErrorText));
            }

            return(Json(result.Data));
        }
Ejemplo n.º 5
0
 private static bool checkIfStorySubscribe(PostOptions po, Newsfeed storyitem)
 {
     if ((po.SubscriptionPhotos == 1 && checkIfPhotoStoryItem(storyitem)) ||
         (po.SubscriptionLinks == 1 && storyitem.Type == Global.LINK) ||
         (po.SubscriptionStatus == 1 && storyitem.Type == Global.TEXT_POST) ||
         (po.SubscriptionVideos == 1 && checkIfVideoStoryItem(storyitem))
         )
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
        //Create post TODO
        public Result <Post> CreatePost(PostOptions postOptions)
        {
            if (postOptions == null)
            {
                return(Result <Post> .CreateFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(postOptions.PostDescription))
            {
                return(Result <Post> .CreateFailed(
                           StatusCode.BadRequest, "Null or empty PostDescription"));
            }

            string userId  = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    project = projectServices.FindProjectById(postOptions.ProjectId);
            Post   post    = new Post
            {
                UserId          = userId,
                Project         = project,
                PostDescription = postOptions.PostDescription
            };

            _db.Add(post);

            var rows = 0;

            try
            {
                rows = _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <Post> .CreateFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <Post> .CreateFailed(
                           StatusCode.InternalServerError,
                           "Post could not be updated"));
            }

            return(Result <Post> .CreateSuccessful(post));
        }
Ejemplo n.º 7
0
        public async Task OnGetAsync(string author, string category, int?year, int?month, int?day)
        {
            string categoryString = String.IsNullOrEmpty(category) ? "all" : category;

            options = new PostOptions()
            {
                Author    = author,
                Category  = categoryString,
                Year      = year,
                Month     = month,
                Day       = day,
                StartDate = null
            };

            Title = $"{ToTitleCase(categoryString)} {GetAuthorString(author)} {GetDateString(year, month, day)}";
            Posts = await _postsRepository.GetByOptionsAsync(options);

            ViewData["Title"] = Title;
        }
Ejemplo n.º 8
0
        //not used
        public IQueryable <Post> ListPosts(PostOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = _db
                        .Set <Post>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.PostDescription))
            {
                query = query.Where(c => c.PostDescription == options.PostDescription);
            }
            query = query.Take(500);

            return(query);
        }
        public HttpResponseMessage Post(PostOptions options)
        {
            if (!this.ModelState.IsValid)
            {
                var errors = this.ModelState.Values
                             .SelectMany(v => v.Errors)
                             .Select(e => (object)e.Exception ?? e.ErrorMessage);
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }

            var repo      = DataContext.Instance().GetRepository <Injection>();
            var injection = new Injection {
                Message = options.Message,
            };

            repo.Insert(injection);

            return(this.Request.CreateResponse(HttpStatusCode.Created, injection));
        }
Ejemplo n.º 10
0
        public async Task <Response <PostList> > ReadPostBySlugAsync(string slug, PostOptions options = null)
        {
            var requestUri = new StringBuilder();

            requestUri.Append($"/ghost/api/v3/content/posts/slug/{slug}/?key={_apiKey}");

            if (options != null)
            {
                // Adds optional request information to the call.
                requestUri.Append(options.Include != Include.None
                    ? $"&include={options.Include.GetDescriptions()}"
                    : string.Empty);
                requestUri.Append(options.Format != Format.None
                    ? $"&formats={options.Format.GetDescriptions()}"
                    : string.Empty);
                requestUri.Append(options.Fields != PostFields.None
                    ? $"&fields={options.Fields.GetDescriptions()}"
                    : string.Empty);
            }

            return(await GetRequestAsync <PostList>(requestUri));
        }
Ejemplo n.º 11
0
 public abstract List<Post> GetPostsOfCategory(int categoryId, PostOptions option, int indexOfPage, int sizeOfPage, out int total);
 public override List<Post> GetPostsOfCategory(int categoryId, PostOptions option, int indexOfPage,
     int sizeOfPage, out int total)
 {
     var context = new BlogsEntities();
     List<tblBlogs_Posts> list;
     switch (option)
     {
         case PostOptions.Published:
             total =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     Where(item => item.Published).Count();
             list =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     Where(item => item.Published).OrderByDescending(item => item.CreatedDate).Skip(indexOfPage*
                                                                                                    sizeOfPage).
                     Take(sizeOfPage).ToList();
             break;
         case PostOptions.NotPublished:
             total =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     Where(item => item.Published == false).Count();
             list =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     Where(item => item.Published == false).OrderByDescending(item => item.CreatedDate).Skip(
                     indexOfPage*sizeOfPage).Take(sizeOfPage).ToList();
             break;
         default:
             total =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     Count();
             list =
                 context.tblBlogs_Categories.Where(item => item.Id == categoryId).SelectMany(item => item.Posts).
                     OrderByDescending(item => item.CreatedDate).
                     Skip(indexOfPage*sizeOfPage).Take(sizeOfPage).ToList();
             break;
     }
     return list.ConvertAll(obj => Convert(obj));
 }
 public override List<Post> GetPostsOfBlog(int blogId, PostOptions option)
 {
     var context = new BlogsEntities();
     List<tblBlogs_Posts> list;
     switch (option)
     {
         case PostOptions.Published:
             list =
                 context.tblBlogs_Posts.Where(item => item.BlogId == blogId && item.Published).OrderByDescending(
                     item => item.CreatedDate).ToList();
             break;
         case PostOptions.NotPublished:
             list =
                 context.tblBlogs_Posts.Where(item => item.BlogId == blogId && item.Published == false).
                     OrderByDescending(item => item.CreatedDate).ToList();
             break;
         default:
             list =
                 context.tblBlogs_Posts.Where(item => item.BlogId == blogId).OrderByDescending(
                     item => item.CreatedDate).ToList();
             break;
     }
     return list.ConvertAll(obj => Convert(obj));
 }
Ejemplo n.º 14
0
 private static bool checkIfStorySubscribe(PostOptions po, Newsfeed storyitem)
 {
     if ((po.SubscriptionPhotos == 1 && checkIfPhotoStoryItem(storyitem)) ||
         (po.SubscriptionLinks == 1 && storyitem.Type == Global.LINK) ||
         (po.SubscriptionStatus == 1 && storyitem.Type == Global.TEXT_POST) ||
         (po.SubscriptionVideos == 1 && checkIfVideoStoryItem(storyitem))
        )
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 15
0
		private RootElement CreateRoot ()
		{
			Description = new MyEntryElement ("title", null, false, UIReturnKeyType.Default);
			FirstComment = new MyEntryElement ("first comment", null, false, UIReturnKeyType.Default);
			
			if (eventImage != null)
			{
				return new RootElement ("post") {
					new Section () {  Description, },
					new Section() { FirstComment, }
				};
			}
			else
			{
				createAlbumCbx = new BooleanElement (Locale.GetText ("create album"), false);
				createAlbumCbx.ValueChanged += (sender, e) => 
				{
					postOptions = createAlbumCbx.Value ? PostOptions.CreateAlbum : PostOptions.PostNew;
				};
				return new RootElement ("post") {
					new Section () {  Description, },
					new Section() { FirstComment, },
					new Section() { createAlbumCbx }
				};
			}
		}
Ejemplo n.º 16
0
        public static List <Newsfeed> getNewsfeedByUserId(string UserId, int top)
        {
            List <Newsfeed> lstNewsfeed = new List <Newsfeed>();

            List <UserFriendsBO> lstfriends = new List <UserFriendsBO>();

            MongoCollection <Newsfeed>          objCollection  = db.GetCollection <Newsfeed>("c_Wall");
            MongoCollection <PostHidSpamStatus> objCollection2 = db.GetCollection <PostHidSpamStatus>("c_PostStatus");
            MongoCollection <PostOptions>       objCollection3 = db.GetCollection <PostOptions>("c_PostOption");

            objCollection.EnsureIndex("Type");

            //get all friends
            lstfriends = FriendsDAL.getAllFriendsListName(UserId, Global.CONFIRMED);

            //against every friend
            foreach (UserFriendsBO friend in lstfriends)
            {
                ////get hidden posts or posts reported as spam
                var query1 = Query.And(
                    Query.EQ("UserId", ObjectId.Parse(UserId)),
                    Query.EQ("FriendId", ObjectId.Parse(friend.FriendUserId)),
                    Query.Or(
                        Query.EQ("PostStatus", 1),
                        Query.EQ("PostStatus", 2))
                    );

                var hiddenposts = objCollection2.Find(query1);

                //get all posts of a friend
                var query = Query.EQ("WallOwnerUserId", ObjectId.Parse(friend.FriendUserId));

                var cursor = objCollection.Find(query);
                cursor.Limit = top;
                var sortBy = SortBy.Descending("AddedDate");
                cursor.SetSortOrder(sortBy);

                //for every post of friend
                foreach (var item in cursor)
                {
                    //add post to list
                    lstNewsfeed.Add(item);
                }

                //against every hidden post
                foreach (var po in hiddenposts)
                {
                    //check friends posts in list
                    foreach (Newsfeed storyitem in lstNewsfeed.ToList())
                    {
                        //if hidden post id is equal to friends post id then remove it from list

                        if (po.PostId.ToString().Equals(storyitem._id.ToString()))
                        {
                            lstNewsfeed.Remove(storyitem);
                        }
                    }
                }

                // get updates type for a friend

                var querysub = Query.And(
                    Query.EQ("UserId", ObjectId.Parse(UserId)),
                    Query.EQ("FriendId", ObjectId.Parse(friend.FriendUserId))
                    );

                var types = objCollection3.Find(querysub);

                if (types.Count() != 0)
                {
                    // int AllSub = 0;
                    int         PhotoSub     = 0;
                    int         LinksSub     = 0;
                    int         VideoSub     = 0;
                    int         VideolinkSub = 0;
                    int         StatusSub    = 0;
                    int         updatestype  = 0;
                    PostOptions postoption   = null;
                    foreach (PostOptions po in types)
                    {
                        updatestype = po.UpdatesType;
                        //  AllSub = po.SubscriptionAll;
                        PhotoSub     = po.SubscriptionPhotos;
                        LinksSub     = po.SubscriptionLinks;
                        VideoSub     = po.SubscriptionVideos;
                        VideolinkSub = po.SubscriptionVideoLinks;
                        StatusSub    = po.SubscriptionStatus;
                        postoption   = po;
                        break;
                    }
                    if (PhotoSub == 1 && LinksSub == 1 && VideoSub == 1 && VideolinkSub == 1 && StatusSub == 1)
                    {
                        foreach (Newsfeed storyitem in lstNewsfeed.ToList())
                        {
                            //if hidden post id is equal to friends post id then remove it from list
                            if (friend.FriendUserId.Equals(storyitem.PostedByUserId.ToString()))
                            {
                                lstNewsfeed.Remove(storyitem);
                            }
                        }
                    }
                    else
                    {
                        //against every story of friend
                        foreach (Newsfeed storyitem in lstNewsfeed.ToList())
                        {
                            //if friend story type is different from updates type then remove it from list
                            switch (updatestype)
                            {
                            case 1:    //all updates


                                break;

                            case 2:    // most updates photos and status messages
                                if (storyitem.Type == Global.TEXT_POST ||
                                    storyitem.Type == Global.PHOTO ||
                                    storyitem.Type == Global.TAG_PHOTO ||
                                    storyitem.Type == Global.TAG_POST)
                                {
                                }
                                else
                                {
                                    lstNewsfeed.Remove(storyitem);
                                }
                                break;

                            case 3:    // only important
                                if (storyitem.Type == Global.PROFILE_CHANGE)
                                {
                                }
                                else
                                {
                                    lstNewsfeed.Remove(storyitem);
                                }
                                break;

                            default:
                                break;
                            }
                            //below is logic for removing items that are unsubscribed
                            if (checkIfStorySubscribe(postoption, storyitem))
                            {
                                lstNewsfeed.Remove(storyitem);
                            }
                        }
                    }
                }
            }

            return(lstNewsfeed);
        }
Ejemplo n.º 17
0
 public abstract List<Post> GetPostsOfBlog(int blogId, PostOptions option);
Ejemplo n.º 18
0
 public abstract List<Post> GetPostsOfBlog(int blogId, PostOptions option, int indexOfPage, int sizeOfPage, out int total);
Ejemplo n.º 19
0
 public abstract List<Post> GetPostsOfCategory(int categoryId, PostOptions option);