public void AddImageToGallery()
        {
            GalleryContext db         = new GalleryContext();
            var            unassigned = db.Images.Include(img => img.Galleries).ToArray();

            var originals = unassigned.Where(img => (img is OriginalImage && img.Galleries.Count == 0));

            // hard code value, take third image
            var galleryimage = originals.ElementAt(3);

            //var galleries =
            //    new SelectList(db.Galleries.ToArray().Select(x => new { value = x.GalleryId, text = x.Name }),
            //    "value", "text", "");

            // hard coded value
            var galleryId = 2;

            if (galleryId != null)
            {
                var gallery = db.Galleries.Find(galleryId);
                if (gallery != null)
                {
                    galleryimage.Galleries.Add(gallery);
                    gallery.Images.Add(galleryimage);
                    db.Entry(galleryimage).State = EntityState.Modified;
                    db.Entry(gallery).State      = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            originals = unassigned.Where(img => (img is OriginalImage && img.Galleries.Count == 0));
        }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "ID,AlbumName,InsertedDateTime,LastUpdatedDatetime,InsertedBy,LastUpdatedBy")] Album album)
        {
            if (ModelState.IsValid)
            {
                TempData["Message"]       = "";
                db.Entry(album).State     = EntityState.Modified;
                album.LastUpdatedBy       = User.Identity.Name;
                album.LastUpdatedDatetime = DateTime.Now;
                db.Entry(album).Property("InsertedBy").IsModified       = false;
                db.Entry(album).Property("InsertedDateTime").IsModified = false;

                string path    = Server.MapPath("~/Content/PatternProject/");
                string Fromfol = getAlbamName(album.ID);
                string Tofol   = album.AlbumName;
                if (directoryExists(path + Fromfol))
                {
                    Directory.Move(path + Fromfol, path + Tofol);
                    db.SaveChanges();
                    TempData["Message"] = "<div class='alert alert-success'><a href='#' class='close' data-dismiss='alert'>&times;</a><strong>Success!</strong> Successfully renamed.</div> ";
                }
                else
                {
                    TempData["Message"] = "<div class='alert alert-danger'><a href='#' class='close' data-dismiss='alert'>&times; Directory</a><strong> " + Fromfol + "</strong> Not found.</div>";
                }
                return(RedirectToAction("Index"));
            }
            return(View(album));
        }
        public async Task <IActionResult> Put(int key, [FromBody] Album album)
        {
            String userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            var entry = await _context.Albums.FindAsync(key);

            if (entry == null)
            {
                return(NotFound());
            }

            if (String.CompareOrdinal(entry.CreatedBy, userId) != 0)
            {
                return(StatusCode(401));
            }

            entry.Desp     = album.Desp;
            entry.IsPublic = album.IsPublic;
            entry.Title    = album.Title;
            _context.Entry(entry).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Updated(album));
        }
        public ActionResult Likes(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Artwork artwork = db.Artworks.Find(Id);

            if (artwork == null)
            {
                return(HttpNotFound());
            }

            int currentLikes = (int)artwork.Likes;

            artwork.Likes = currentLikes + 1;

            if (ModelState.IsValid)
            {
                db.Entry(artwork).State = EntityState.Modified;
                db.SaveChanges();
            }

            artwork = db.Artworks.Find(Id);
            return(PartialView("_Indexpartial", artwork));
        }
        public ActionResult Edit([Bind(Include = "ID,Title,AlbumId")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TempData["Message"] = "";

                    db.Entry(photo).State = EntityState.Modified;
                    db.Entry(photo).Property("InsertedBy").IsModified       = false;
                    db.Entry(photo).Property("InsertedDateTime").IsModified = false;
                    db.Entry(photo).Property("ImageName").IsModified        = false;
                    string path      = Server.MapPath("~/Content/PhotoGallery/");
                    var    ImageName = GetImageName(photo.ID);
                    string Fromfol   = GetAlbumNameByPhotoID(photo.ID) + "/" + ImageName;
                    string Tofol     = setAlbumName(photo.AlbumId) + "/" + ImageName;
                    photo.LastUpdatedBy       = User.Identity.Name;
                    photo.LastUpdatedDatetime = DateTime.Now;
                    System.IO.File.Move(path + Fromfol, path + Tofol);
                    db.SaveChanges();
                    TempData["Message"] = "<div class='alert alert-success'><a href='#' class='close' data-dismiss='alert'>&times;</a><strong>Success!</strong> Successfully Edited.</div> ";
                }
                catch (IOException ex)
                {
                    TempData["Message"] = "<div class='alert alert-danger'><a href='#' class='close' data-dismiss='alert'>&times; </a><strong> " + ex.ToString() + "</strong> </div>";
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.AlbumId = new SelectList(db.ImageGalleries, "ID", "AlbumName", photo.AlbumId);
            return(View(photo));
        }
Beispiel #6
0
        public ActionResult AddPicture(AddPictureModel model, HttpPostedFileBase file)
        {
            var user = db.User.FirstOrDefault(x => x.login == User.Identity.Name);

            if (user == null || !IsItMineGallery(model.galleryId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ViewBag.galleryId = new SelectList(user.Gallery, "id", "name");
            if (file == null)
            {
                ModelState.AddModelError(string.Empty, "You must select an image.");
                return(View(model));
            }

            if (file.ContentLength > 750 * 1000)
            {
                ModelState.AddModelError(string.Empty, "File size must be less than 750 kilobytes.");
            }

            string file_extention = Path.GetExtension(file.FileName).ToLower();

            if (file_extention != ".mpo" && file_extention != ".jpg")
            {
                ModelState.AddModelError(string.Empty, "File extention must be '.mpo' or '.jpg'.");
            }

            if (model.isAdvanced && model.isTo2d && model.leftOrRight < 0 && model.leftOrRight > 1)
            {
                ModelState.AddModelError(string.Empty, "You must choose which of the images (left or right) should be saved in 2D.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Picture picture = new Picture
            {
                description  = model.description,
                galleryId    = model.galleryId,
                CreationDate = DateTime.Now
            };

            db.Picture.Add(picture);
            db.SaveChanges();

            picture = new PictureSaver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Picture")).AnalyzeAndSave(picture, model, file);

            picture.Gallery.LastPicture = picture;
            db.Entry(picture).State     = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Details", "Gallery", new { id = picture.galleryId }));
        }
Beispiel #7
0
 // todo, restore this when I put this token in the assign gallery form: [ValidateAntiForgeryToken]
 public ActionResult Edit(GalleryImage galleryimage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(galleryimage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(galleryimage));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Path")] Photo photo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(photo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(photo));
 }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "PatronID,PatronName,EntityType,ContactPhone,ContactEmail")] Patron patron)
 {
     if (ModelState.IsValid)
     {
         db.Entry(patron).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(patron));
 }
Beispiel #10
0
 public ActionResult Edit([Bind(Include = "ExhibitionID,ExName,StartDate,FinishDate,Venue,City,ExDesc")] Exhibition exhibition)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exhibition).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(exhibition));
 }
Beispiel #11
0
 public ActionResult Edit([Bind(Include = "Id,Name,Password,IsActive")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit(Artist artist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(artist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(artist));
 }
 public ActionResult Edit(Thumbnail thumbnail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thumbnail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(thumbnail));
 }
Beispiel #14
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(album));
 }
        public async Task <IActionResult> Put(string key, [FromBody] Photo pto)
        {
            var entry = await _context.Photos.FindAsync(key);

            if (entry == null)
            {
                return(NotFound());
            }

            string userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            entry.Desp     = pto.Desp;
            entry.IsPublic = pto.IsPublic;
            entry.Title    = pto.Title;
            _context.Entry(entry).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Updated(pto));
        }
Beispiel #16
0
        public async Task <IActionResult> Put(string key, [FromBody] UserDetail usrdtl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid model state"));
            }
            if (string.CompareOrdinal(key, usrdtl.UserID) != 0)
            {
                return(BadRequest("Key is unmatched"));
            }

            var userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }
            // Can not change other user
            if (String.CompareOrdinal(userId, key) != 0)
            {
                return(StatusCode(401));
            }

            var entry = await _context.UserDetails.FindAsync(key);

            if (entry == null)
            {
                return(NotFound());
            }

            entry.DisplayAs             = usrdtl.DisplayAs;
            entry.AlbumCreate           = usrdtl.AlbumCreate;
            entry.PhotoUpload           = usrdtl.PhotoUpload;
            entry.UploadFileMaxSize     = usrdtl.UploadFileMaxSize;
            entry.UploadFileMinSize     = usrdtl.UploadFileMinSize;
            _context.Entry(entry).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Updated(usrdtl));
        }
Beispiel #17
0
 public void Modify(Album album)
 {
     _context.Entry(album).State = EntityState.Modified;
 }
Beispiel #18
0
 public void Modify(Photo photo)
 {
     _context.Entry(photo).State = EntityState.Modified;
 }
 public virtual async Task AddAsync(T entity)
 {
     EntityEntry dbEntityEntry = _context.Entry <T>(entity);
     await _context.Set <T>().AddAsync(entity);
 }
Beispiel #20
0
 public virtual void Update(T entity)
 {
     _dataContext.Entry(entity).State = EntityState.Modified;
 }