Beispiel #1
0
        public ActionResult Edit(GalleryCreateEditModel galleryCreateEditModel)
        {
            Gallery gallery = this.db.Galleries.Find(galleryCreateEditModel.Gallery.Id);

            if(ModelState.IsValid)
            {
                db.Entry(gallery).State = EntityState.Modified;
                gallery.Title = galleryCreateEditModel.Title;
                gallery.Folder = galleryCreateEditModel.Folder;
                gallery.DatePublished = galleryCreateEditModel.DatePublished;
                gallery.URL = galleryCreateEditModel.URL;
                gallery.IsActive = galleryCreateEditModel.IsActive;
                gallery.ModelId = galleryCreateEditModel.SelectedModel;

                db.SaveChanges();
                return RedirectToAction("Manage");
            }
            else
            {
                var viewModel = new GalleryCreateEditModel
                {
                    Gallery = galleryCreateEditModel.Gallery,
                    Title = galleryCreateEditModel.Title,
                    Folder = galleryCreateEditModel.Folder,
                    DatePublished = galleryCreateEditModel.DatePublished,
                    URL = galleryCreateEditModel.URL,
                    IsActive = galleryCreateEditModel.IsActive,
                    SelectedModel = galleryCreateEditModel.Gallery.ModelId
                };

                return View("Edit", viewModel);
            }
        }
Beispiel #2
0
        public ActionResult Create(GalleryCreateEditModel galleryCreateEditModel)
        {
            Gallery gallery = new Gallery();

            if(ModelState.IsValid)
            {
                gallery.Id = Guid.NewGuid();
                gallery.Folder = galleryCreateEditModel.Folder;
                gallery.Title = galleryCreateEditModel.Title;
                gallery.ModelId = galleryCreateEditModel.SelectedModel;
                gallery.DatePublished = galleryCreateEditModel.DatePublished;
                gallery.URL = galleryCreateEditModel.URL;
                gallery.IsActive = false;
                db.Galleries.Add(gallery);
                db.SaveChanges();

                // Create Gallery Folder
                string basePath = "Content/Models/" + gallery.GetModelName(gallery.ModelId).Replace(" ", string.Empty) + "/ImageGalleries";
                DirectoryInfo dInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + basePath);
                dInfo.CreateSubdirectory(gallery.Folder.Replace(" ", string.Empty));

                return RedirectToAction("Manage");
            }

            return View(gallery);
        }
Beispiel #3
0
        public ActionResult Edit(Guid id)
        {
            GalleryCreateEditModel galleryCreateEditModel = new GalleryCreateEditModel();
            galleryCreateEditModel.Gallery = this.db.Galleries.Find(id);

            var viewModel = new GalleryCreateEditModel
            {
                Gallery = galleryCreateEditModel.Gallery,
                Title = galleryCreateEditModel.Gallery.Title,
                Folder = galleryCreateEditModel.Gallery.Folder,
                DatePublished = galleryCreateEditModel.Gallery.DatePublished,
                URL = galleryCreateEditModel.Gallery.URL,
                IsActive = galleryCreateEditModel.Gallery.IsActive,
                SelectedModel = galleryCreateEditModel.Gallery.ModelId
            };

            return View(viewModel);
        }