public virtual IActionResult SaveBlogEdit(EditItemViewModel model) { // Get the blog that is for this controller instance if (Current != null) { // Get the item that needs to be saved IBlogItem blogItem = (model.Id == "") ? new BlogItem() : Current.Get(new BlogHeader() { Id = Current.Parameters.Provider.DecodeId(model.Id) }); // Blog item valid? if (blogItem != null) { // Update the properties of the blog item from the incoming model blogItem.Copy(model); // (Re)Save the blog item back to the blog handler blogItem = Current.Save(blogItem); } else { throw new ItemNotFoundBlogException("Item with id '{id}' not found"); } } // Call the common view handler return(EditBlogCommon(model.Id)); }
/// <summary> /// Save a blog item /// </summary> /// <param name="item">The item to be saved</param> /// <returns>The item once it has been saved</returns> public virtual IBlogItem Save(IBlogItem item) { // Define the response IBlogItem response = null; // Check and see if the blog item exists in the local item list first IBlogItem foundItem = items.Headers.Where(x => x.Header.Id == item.Header.Id).FirstOrDefault(); if (foundItem == null) { item.Header.Id = NewId(); // Generate a new Id and assign it items.Headers.Add((BlogItem)item); // Add the item response = item; // Assign the data to the response } else { foundItem.Copy(item); // Copy the data in (don't repoint the reference) response = foundItem; // Assign the data to the response } // Return the item back to the caller return(response); }