Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        //
        // 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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }