Example #1
0
 public IActionResult Create(GalleryViewModel gallery)
 {
     if (ModelState.IsValid)
     {
         Gallery svm = new Gallery();
         svm.Name         = gallery.Name;
         svm.IsPublished  = gallery.IsPublished;
         svm.Id           = gallery.Id;
         svm.ModifiedBy   = User.Identity.Name ?? "username";
         svm.ModifiedDate = DateTime.Now;
         svm.AddedBy      = User.Identity.Name ?? "username";
         svm.AddedDate    = DateTime.Now;
         galleryService.CreateGallery(svm);
         galleryService.SaveGallery();
     }
     return(RedirectToAction("Index"));
 }
Example #2
0
        public ActionResult Create(GalleryData gallery)
        {
            try
            {
                if (gallery != null && !string.IsNullOrWhiteSpace(gallery.Name))
                {
                    gallery = GalleryService.CreateGallery(gallery.Name, User);
                }
                else
                {
                    ModelState.AddModelError("Error", "A gallery name is required");
                }
            }
            catch (GalleryAlreadyExistsException)
            {
                ModelState.AddModelError("Error", "A gallery with the same name already exists");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", "Unable to create gallery. " + ex.Message);
            }

            return(PartialView("_CreateGallery", gallery));
        }