/// <summary> /// BlogManagePartial loads the blog management partial using blog id /// </summary> /// <param name="id">blog post id</param> /// <returns></returns> public ActionResult BlogManagePartial(int id = 0) { BlogEntryModel model = new BlogEntryModel(); SIEBUEntities db = new SIEBUEntities(); Store_NewsItem cur_blog = db.Store_NewsItem.FirstOrDefault(ni => ni.sn_id == id); if (cur_blog != null) model = new BlogEntryModel(id, expanded: true, db: db); return PartialView("_BlogManagePartial", model); }
public ActionResult UpdateBlog(BlogEntryModel update) { SIEBUEntities db = new SIEBUEntities(); Store_NewsItem target_entry = db.Store_NewsItem.FirstOrDefault(ni => ni.sn_id == update.id); //if no id is given, create new blog entry bool add_new = false; if (target_entry == null) { add_new = true; target_entry = new Store_NewsItem(); target_entry.store_id = update.store_id; target_entry.author_id = WebSecurity.CurrentUserId; target_entry.date_added = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); } target_entry.title = update.title; target_entry.last_modified = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); target_entry.description = update.description; target_entry.text = update.body_text; target_entry.is_featured = update.is_featured; if (update.is_featured) { target_entry.featured_since = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); } else { target_entry.featured_since = null; } target_entry.is_draft = update.is_draft; if (add_new) { db.Store_NewsItem.Add(target_entry); db.SaveChanges(); } //if the update is not equal to the target image if (target_entry.img == null || !(update.img + "").Contains(target_entry.img)) //target_entry.img != update.img) target_entry.img = update.img != null ? ImageController.UploadFile(update.img, update.store_id + "" + target_entry.sn_id) : null; //no unique file name required + "" + target_entry.last_modified.Value.ToString("ffffff") db.SaveChanges(); return Json(target_entry.sn_id, JsonRequestBehavior.AllowGet); }