Beispiel #1
0
        /// <summary>
        /// edit post to page
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> EditPost(PostModel post)
        {
            post.PostedBy   = CurrentUser.UserID;
            post.PostedDate = DateTime.Now;
            ModelState.Remove("post.PostedBy");
            ModelState.Remove("post.PostedDate");
            post.PostedByName   = CurrentUser.FullName;
            post.PostedByAvatar = CurrentUser.ProfilePicture;

            if (ModelState.IsValid)
            {
                try
                {
                    BroadcastPost model = _post.AddPost(post);
                    await _broadcaster.AddPost(model, post.broadCastType);

                    return(Ok(model.Post));
                }
                catch (Exception ex)
                {
                    Logs.Error("Error adding post to page", ex);
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState.JsonValidation()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// add post to page
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> DeletePost(PostModel post)
        {
            if (post.PostedBy != CurrentUser.UserID)
            {
                ModelState.AddModelError("Unauthorized", "You are not authorized to do that");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    BroadcastPost model = _post.DeletePost(post);
                    await _broadcaster.DeletePost(model, post.broadCastType);

                    return(Ok(model.Post));
                }
                catch (Exception ex)
                {
                    Logs.Error("Error adding post to page", ex);
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState.JsonValidation()));
            }
        }
        /// <summary>
        /// broadcast post to page
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task BroadcastDeletePostToWeb(BroadcastPost model)
        {
            IList <string> connectionIDs = _user.GetFollowerListByConnectID(model.Post.PostedBy, Enums.PageType.Profile, Enums.FriendshipStatus.FA)
                                           .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList();

            await _postBroadCaster.Clients.Clients(connectionIDs)
            .deletePost(model.Post);
        }
        /// <summary>
        /// Select a broad casting way to delete post to a page
        /// </summary>
        /// <param name="post"></param>
        public async Task DeletePost(BroadcastPost model, Enums.BroadCastType BroadCastType)
        {
            try
            {
                switch (BroadCastType)
                {
                case Enums.BroadCastType.Web:
                    await BroadcastDeletePostToWeb(model);

                    break;
                }
            }
            catch (Exception ex)
            {
                ExceptionService.LogError("Error broadcasting post to page", ex);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Select a broad casting way to new post to a page
        /// </summary>
        /// <param name="post"></param>
        public async Task AddPost(BroadcastPost model, Enums.BroadCastType BroadCastType)
        {
            try
            {
                switch (BroadCastType)
                {
                case Enums.BroadCastType.Web:
                    await BroadcastAddPostToWeb(model);

                    break;
                }
            }
            catch (Exception ex)
            {
                Logs.Error("Error broadcasting post to page", ex);
            }
        }