Esempio n. 1
0
        public async Task <IActionResult> New(EF.GalleryPhoto args, IFormFile file)
        {
            IFormFile uploadedImage = file;

            if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                // Add photo
                var pid = await new BLL.Photo(unitOfWork).Add(_environment, file);

                // Add GalleryPhoto
                await new BLL.GalleryPhoto(unitOfWork).Add(new EF.GalleryPhoto {
                    GalleryId    = args.GalleryId,
                    PhotoId      = pid,
                    Title        = args.Title,
                    Description  = args.Description,
                    DateCreated  = DateTime.Now,
                    CreatedBy    = User.Identity.Name,
                    ModifiedBy   = User.Identity.Name,
                    DateModified = DateTime.Now
                });

                return(Redirect("~/Gallery/" + args.GalleryId + "/Photos/"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "No image to upload");
                return(View(args));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(EF.GalleryPhoto args)
        {
            var gallery = await new BLL.Gallery(unitOfWork).Get(new EF.Gallery {
                GalleryId = args.GalleryId
            });

            ViewData["Title"] = "Gallery/" + gallery.Name;
            ViewBag.Data      = await new BLL.GalleryPhoto(unitOfWork).Find(args);
            return(View(new EF.GalleryPhoto {
                GalleryId = args.GalleryId
            }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(EF.GalleryPhoto args, IFormFile file)
        {
            // Update Photo
            IFormFile uploadedImage = file;

            if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                // Delete GalleryPhoto
                await new BLL.GalleryPhoto(unitOfWork).Delete(new EF.GalleryPhoto {
                    GalleryId = args.GalleryId, PhotoId = args.PhotoId
                });

                // Delete photo
                await new BLL.Photo(unitOfWork).Delete(args.PhotoId, _environment);

                // Add photo
                var pid = await new BLL.Photo(unitOfWork).Add(_environment, file);

                // Add GalleryPhoto
                await new BLL.GalleryPhoto(unitOfWork).Add(new EF.GalleryPhoto
                {
                    GalleryId    = args.GalleryId,
                    PhotoId      = pid,
                    Title        = args.Title,
                    Description  = args.Description,
                    DateCreated  = DateTime.Now,
                    CreatedBy    = User.Identity.Name,
                    ModifiedBy   = User.Identity.Name,
                    DateModified = DateTime.Now
                });

                return(Redirect("~/Gallery/" + args.GalleryId + "/Photos/"));
            }

            args.ModifiedBy   = User.Identity.Name;
            args.DateModified = DateTime.Now;
            await new BLL.GalleryPhoto(unitOfWork).Edit(args);

            return(Redirect("~/Gallery/" + args.GalleryId + "/Photos/"));
        }