public ActionResult Create(Picture picture) { if (ModelState.IsValid) { if (picture.SavedContentId.HasValue) { picture.ContentId = picture.SavedContentId.Value; db.Frames.Add(picture); db.SaveChanges(); return this.RestoreReferrer() ?? RedirectToAction("Index", "Frame"); } else { TempData["_newPicture"] = picture; return RedirectToAction("Upload", "Picture"); } } this.FillTemplatesSelectList(db, FrameTypes.Picture, picture.TemplateId); FillPicturesSelectList(); FillModesSelectList(); return View(picture); }
// // GET: /Picture/Create public ActionResult Create() { Frame frame = TempData[FrameController.SelectorFrameKey] as Frame; if (frame == null || frame.PanelId == 0) { return RedirectToAction("Create", "Frame"); } Picture picture = new Picture(frame, db); this.FillTemplatesSelectList(db, FrameTypes.Picture); FillPicturesSelectList(); FillModesSelectList(); return View(picture); }
public ActionResult Upload(Picture picture, HttpPostedFileBase file) { if (ModelState.IsValid && file != null && file.ContentLength > 0) { // TODO: EditorFor, validate file type string ext = Path.GetExtension(file.FileName).Replace(".", "").ToUpper(); if (Picture.SupportedFormats.Contains(ext)) { byte[] buffer = null; using (BinaryReader reader = new BinaryReader(file.InputStream)) { buffer = reader.ReadBytes(file.ContentLength); } picture.Content = new Models.Content { Type = ContentTypes.ContentType_Picture, Name = Path.GetFileName(file.FileName), Data = buffer, }; db.Frames.Add(picture); db.SaveChanges(); return this.RestoreReferrer() ?? RedirectToAction("Index", "Frame"); } } this.FillTemplatesSelectList(db, FrameTypes.Picture, picture.TemplateId); FillPicturesSelectList(); FillModesSelectList(); ViewBag.MaxImageSize = Setting.GetSetting(db, Setting.Keys.MaxImageSize).IntValuePositive; return View(picture); }
public ActionResult Edit(Picture picture) { if (ModelState.IsValid) { db.Entry(picture).State = EntityState.Modified; db.SaveChanges(); return this.RestoreReferrer() ?? RedirectToAction("Index", "Frame"); } this.FillTemplatesSelectList(db, FrameTypes.Picture, picture.TemplateId); FillPicturesSelectList(picture.ContentId); FillModesSelectList(picture.Mode); return View(picture); }