public static EditablePost GetEditedPost(TreeListEditFormTemplateContainer container)
        {
            var post = new EditablePost
            {
                From          = (string)DataBinder.Eval(container.DataItem, "From"),
                Subject       = (string)DataBinder.Eval(container.DataItem, "Subject"),
                PostDate      = (DateTime)(DataBinder.Eval(container.DataItem, "PostDate") ?? new DateTime()),
                Text          = (string)DataBinder.Eval(container.DataItem, "Text"),
                HasAttachment = (bool?)DataBinder.Eval(container.DataItem, "HasAttachment"),
                IsNew         = (bool?)DataBinder.Eval(container.DataItem, "IsNew"),
                ParentID      = (int?)DataBinder.Eval(container.DataItem, "ParentID")
            };
            var postId = DataBinder.Eval(container.DataItem, "PostID");

            int postIdToExcludeFromParentList = postId != null
                ? (int)DataBinder.Eval(container.DataItem, "PostID")
                : -1;

            post.PostLookups.Add(new PostLookup(0, ""));

            post.PostLookups.AddRange(NewsGroupsProvider.GetEditablePosts()
                                      .Where(p => p.PostID != postIdToExcludeFromParentList)
                                      .Select(p => new PostLookup(p.PostID, p.From)));

            return(post);
        }
        public static void DeletePost(int id)
        {
            EditablePost postToDelete = GetEditablePost(id);

            if (postToDelete != null)
            {
                DeleteChildPosts(postToDelete);
            }
        }
 public ActionResult InlineEditingWithTemplateAddNewPostPartial(EditablePost post)
 {
     if (ModelState.IsValid)
     {
         NewsGroupsProvider.InsertPost(post);
     }
     else
     {
         ViewData["EditNodeError"] = "Please, correct all errors.";
     }
     return(InlineEditingWithTemplatePartial());
 }
        static void DeleteChildPosts(EditablePost post)
        {
            List <EditablePost> childPosts = GetEditableChildPosts(post.PostID);

            if (childPosts != null)
            {
                foreach (EditablePost childPost in childPosts)
                {
                    DeleteChildPosts(childPost);
                }
            }
            GetEditablePosts().Remove(post);
        }
        public static void UpdatePost(EditablePost post)
        {
            EditablePost postToUpdate = GetEditablePost(post.PostID);

            if (postToUpdate != null)
            {
                postToUpdate.Subject       = post.Subject;
                postToUpdate.From          = post.From;
                postToUpdate.PostDate      = post.PostDate;
                postToUpdate.Text          = post.Text;
                postToUpdate.IsNew         = post.IsNew;
                postToUpdate.HasAttachment = post.HasAttachment;
                postToUpdate.ParentID      = post.ParentID;
            }
        }
 public ActionResult InlineEditingWithTemplateUpdatePostPartial(EditablePost post)
 {
     if (ModelState.IsValid)
     {
         NewsGroupsProvider.UpdatePost(post);
         if (post.ParentID != null)
         {
             NewsGroupsProvider.MovePost(post.PostID, post.ParentID);
         }
     }
     else
     {
         ViewData["EditNodeError"] = "Please, correct all errors.";
     }
     return(InlineEditingWithTemplatePartial());
 }
Exemple #7
0
        public async Task <IActionResult> AddOrUpdate(int postId, [FromForm] EditablePost newPost)
        {
            bool isNew = postId == 0;

            if (isNew && _blogContext.Posts.Any(c => c.UrlSegment == newPost.UrlSegment))
            {
                ModelState.AddModelError("Blog.ViewModels.NewPost.Permalink", string.Format("Url Segment {0} already exists", newPost.UrlSegment));
            }

            if (ModelState.IsValid)
            {
                var dbPost = _mapper.Map <Data.Models.Post>(newPost);
                dbPost.LastModifiedDate = DateTime.Today;
                _blogContext.Update(dbPost); // Performs add or update
                await _blogContext.SaveChangesAsync();

                return(Ok(isNew ? "Post Added" : "Post Updated"));
            }
            return(BadRequest(ModelState));
        }
 public static void InsertPost(EditablePost newPost)
 {
     newPost.PostID = GetNewEditablePostID();
     GetEditablePosts().Add(newPost);
 }