public ActionResult Create(ArticleCreateViewModel model) { if (ModelState.IsValid) { SaveImage(model); ArticleManager.Create(new Article { Added = DateTime.Now, AuthorId = AccountHelper.GetLoggedUserId(), Content = model.Content, Image = model.ImageUrl, ImageThumb = model.ImageThumbUrl, ShortInfo = model.ShortInfo, Title = model.Title }); ArticleManager.Save(); return RedirectToAction("Index"); } return View(model); }
private bool SaveImage(ArticleCreateViewModel model) { var file = model.Image; if (file == null) { return false; } string fileName = Guid.NewGuid().ToString(); string path = Server.MapPath("~/Images/Articles/"); if (!(UploadImage(file, fileName, path, "format=jpg") && UploadImage(file, fileName, path + "Thumbs\\", "width=156&format=jpg"))) { return false; } model.ImageUrl = path + fileName + ".jpg"; model.ImageThumbUrl = path + "Thumbs\\" + fileName + ".jpg"; return true; }
public ActionResult Update(Guid? id) { if (id.HasValue) { var entity = ArticleManager.FindById(id.Value); var model = new ArticleCreateViewModel { Title = entity.Title, ShortInfo = entity.ShortInfo, ImageUrl = entity.Image, DateAdded = entity.Added, Content = entity.Content, AuthorId = entity.AuthorId, Id = entity.Id }; return View("Update", model); } return RedirectToAction("Index"); }