public ActionResult Add([Bind(Prefix="NewsItem")]NewsItem newsItem, UploadImagePopupViewModel image) { NewsItemEditViewModel newsItemEditViewModel = new NewsItemEditViewModel(); newsItemEditViewModel.NewsItem = newsItem; newsItemEditViewModel.UploadImagePopupViewModel = image; return ManageNewsItem(newsItemEditViewModel); }
public ActionResult Edit(Guid id) { NewsItem newsItem = NewsItemManager.GetByID(id); PrepareImageMetaData(newsItem); NewsItemEditViewModel newsItemEditViewModel = new NewsItemEditViewModel(); newsItemEditViewModel.NewsItem = newsItem; newsItemEditViewModel.UploadImagePopupViewModel = new UploadImagePopupViewModel(); newsItemEditViewModel.UploadImagePopupViewModel.ImageMetaData = newsItem.Image; return View(newsItemEditViewModel); }
public ActionResult Edit(Guid id, FormCollection formCollection) { NewsItem newsItem = NewsItemManager.GetByID(id); UpdateModel<NewsItem>(newsItem, "NewsItem"); //This object represents a file the user has uploaded... UploadImagePopupViewModel uploadImagePopupViewModel = new UploadImagePopupViewModel(); UpdateModel<UploadImagePopupViewModel>(uploadImagePopupViewModel); NewsItemEditViewModel newsItemEditViewModel = new NewsItemEditViewModel(); newsItemEditViewModel.NewsItem = newsItem; newsItemEditViewModel.UploadImagePopupViewModel = uploadImagePopupViewModel; return ManageNewsItem(newsItemEditViewModel); }
public ActionResult Add() { NewsItemEditViewModel newsItemEditViewModel = new NewsItemEditViewModel(); newsItemEditViewModel.UploadImagePopupViewModel = new UploadImagePopupViewModel(); return View(newsItemEditViewModel); }
/// <summary> /// The NewsItemEditViewModel is passed through since this is the model which we need to pass back to the view :) /// </summary> /// <param name="newsItemEditViewModel"></param> /// <returns></returns> private ActionResult ManageNewsItem(NewsItemEditViewModel newsItemEditViewModel) { IListenToUser user = (IListenToUser)this.HttpContext.User; NewsItem newsItem = newsItemEditViewModel.NewsItem; UploadImagePopupViewModel image = newsItemEditViewModel.UploadImagePopupViewModel; try { //For time being we only want to be able to add news to ListenToManchester newsItem.TargetSites = new List<Site>(); newsItem.TargetSites.Add(this.GetSite()); //Until we've decided how publishing will work... newsItem.IsPublished = true; if (image.ImageMetaData != null) { //We have an image! //Assign it to the newsitem //The previous image wont be deleted, but we dont really care at this point! newsItem.Image = image.ImageMetaData; } NewsItemManager.Save(newsItem, user.UserCredentials); } catch (ValidationException e) { e.AddToModelState(ViewData.ModelState, "NewsItem"); } //If the model isnt valid if (!ViewData.ModelState.IsValid) { return View(newsItemEditViewModel); } return RedirectToNewsItem(newsItem); }