/// <summary> /// Inserts Photo into the Photos Table /// </summary> /// <param name="photo">A new populated photo.</param> /// <param name="galleryPhoto">The gallery photo.</param> /// <param name="adminPhotos">Photos to be used in admin section</param> /// <returns>Insert Count</returns> public int Insert(Photo photo, GalleryPhoto galleryPhoto, GalleryPhoto adminPhotos) { SqlParameter[] parameters = { _database.MakeParameter("@Title", SqlDbType.NVarChar, 100, photo.Title), _database.MakeParameter("@GalleryId", SqlDbType.Int, 4, photo.GalleryId), _database.MakeParameter("@Description", SqlDbType.NVarChar, 255, photo.Description), _database.MakeParameter("@DateTaken", SqlDbType.DateTime, 8, photo.DateTaken), _database.MakeParameter("@OriginalImage", SqlDbType.Image, galleryPhoto.OriginalImage.Length, galleryPhoto.OriginalImage), _database.MakeParameter("@DisplayImage", SqlDbType.Image, galleryPhoto.DisplayImage.Length, galleryPhoto.DisplayImage), _database.MakeParameter("@ThumbnailImage", SqlDbType.Image, galleryPhoto.ThumbnailImage.Length, galleryPhoto.ThumbnailImage), _database.MakeParameter("@AdminThumbnail", SqlDbType.Image, adminPhotos.ThumbnailImage.Length, adminPhotos.ThumbnailImage), _database.MakeParameter("@AdminFullsizeImage", SqlDbType.Image, adminPhotos.DisplayImage.Length, adminPhotos.DisplayImage), _database.MakeParameter("@Profile", SqlDbType.NVarChar, 50, photo.Profile) }; try { _database.NonQuery("Photo_Insert", parameters); } catch (Exception) { throw; } return(1); }
public ActionResult UnpublishPhotoConfirmed(int id) { GalleryPhoto galleryPhoto = db.GalleryPhotos.Find(id); galleryPhoto.Published = false; db.SaveChanges(); return(RedirectToAction("Admin", "Home")); }
public ActionResult DeletePhotoConfirmed(int id) { GalleryPhoto galleryPhoto = db.GalleryPhotos.Find(id); db.GalleryPhotos.Remove(galleryPhoto); db.SaveChanges(); return(RedirectToAction("ProfilePage", "Home", new { id = User.Identity.GetUserId() })); }
public void AddPhotoToGallery(long galleryId, List <string> photosUrl) { foreach (var photoUrl in photosUrl) { var galleryPhoto = new GalleryPhoto(); galleryPhoto.GalleryId = galleryId; galleryPhoto.ImageUrl = photoUrl; _galleryPhotoRepository.Add(galleryPhoto); } }
public ActionResult EditPhoto([Bind(Include = "Id,File,Caption,AuthorId,Created,Published,Ignored,ChapterId")] GalleryPhoto galleryPhoto) { if (ModelState.IsValid) { db.GalleryPhotos.Attach(galleryPhoto); db.Entry(galleryPhoto).Property("Caption").IsModified = true; db.SaveChanges(); return(RedirectToAction("ProfilePage", "Home", new { id = User.Identity.GetUserId() })); } return(View(galleryPhoto)); }
/// <summary> /// Updates the photos in the database /// </summary> /// <param name="photoID">Id of photo row</param> /// <param name="photos">the class containing the resized/new images</param> /// <returns></returns> public int UpdateImages(int photoID, GalleryPhoto photos) { SqlParameter[] parameters = { _database.MakeParameter("@PhotoID", SqlDbType.Int, 4, photoID), _database.MakeParameter("@OriginalImage", SqlDbType.Image, photos.OriginalImage.Length, photos.OriginalImage), _database.MakeParameter("@DisplayImage", SqlDbType.Image, photos.DisplayImage.Length, photos.DisplayImage), _database.MakeParameter("@ThumbnailImage", SqlDbType.Image, photos.ThumbnailImage.Length, photos.ThumbnailImage) }; int updateCount = _database.NonQuery("Photo_ImagesUpdate", parameters); return(updateCount); }
/// <summary> /// Updates the photos in the database /// </summary> /// <param name="photoID">Id of photo row</param> /// <param name="photos">the class containing the resized/new images</param> /// <param name="commandText"></param> /// <returns></returns> public int UpdateImages(int photoID, GalleryPhoto photos, string commandText) { DbParameter[] parameters = { DbClient.MakeParameter("@PhotoID", DbType.Int32, 4, photoID), DbClient.MakeParameter("@OriginalImage", DbType.Binary, photos.OriginalImage.Length, photos.OriginalImage), DbClient.MakeParameter("@DisplayImage", DbType.Binary, photos.DisplayImage.Length, photos.DisplayImage), DbClient.MakeParameter("@ThumbnailImage", DbType.Binary, photos.ThumbnailImage.Length, photos.ThumbnailImage) }; int updateCount = DbClient.NonQuery(commandText, parameters); return(updateCount); }
// GET: Home/UnpublishPhoto/5 public ActionResult UnpublishPhoto(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GalleryPhoto galleryPhoto = db.GalleryPhotos.Find(id); if (galleryPhoto == null) { return(HttpNotFound()); } return(View(galleryPhoto)); }
public async Task <IActionResult> AddItem(List <FaceFound> faces, string imageUrl) { var newfaces = FindEmotions(faces); var newPhoto = new GalleryPhoto { PhotoUrl = imageUrl, FacesFound = newfaces, TimeCreated = DateTime.Now }; await _context.GalleryPhotos.AddAsync(newPhoto); await _context.SaveChangesAsync(); _memoryCache.Remove("GalleryPhotos"); return(new OkResult()); }
/// <summary> /// Inserts Photo into the Photos Table /// </summary> /// <param name="photo">A new populated photo.</param> /// <param name="galleryPhoto"></param> /// <param name="adminPhotos">Photos to be used in admin section</param> /// <returns>Insert Count</returns> public int Insert(Photo photo, GalleryPhoto galleryPhoto, GalleryPhoto adminPhotos, string commandText) { DbParameter[] parameters = { DbClient.MakeParameter("@Title", DbType.String, 100, photo.Title), DbClient.MakeParameter("@Description", DbType.String, 255, photo.Description), DbClient.MakeParameter("@DateTaken", DbType.DateTime, 8, photo.DateTaken), DbClient.MakeParameter("@GalleryID", DbType.Int32, 4, photo.GalleryID), DbClient.MakeParameter("@OriginalImage", DbType.Binary, galleryPhoto.OriginalImage.Length, galleryPhoto.OriginalImage), DbClient.MakeParameter("@DisplayImage", DbType.Binary, galleryPhoto.DisplayImage.Length, galleryPhoto.DisplayImage), DbClient.MakeParameter("@ThumbnailImage", DbType.Binary, galleryPhoto.ThumbnailImage.Length, galleryPhoto.ThumbnailImage), DbClient.MakeParameter("@AdminThumbnail", DbType.Binary, adminPhotos.ThumbnailImage.Length, adminPhotos.ThumbnailImage), DbClient.MakeParameter("@AdminFullsizeImage", DbType.Binary, adminPhotos.DisplayImage.Length, adminPhotos.DisplayImage), DbClient.MakeParameter("@Profile", DbType.String, 50, photo.Profile) }; return(DbClient.NonQuery(commandText, parameters)); }
public void Upload(string token, byte[] image, int galleryId, string imageFormat) { bool isTokenValid = UserLogic.IsValidToken(token); //Check for the validity of the token. if (!isTokenValid) { throw new InvalidTokenException(); } //User user = UserLogic.RetrieveUserByToken(token); Photo photo = new Photo { GalleryId = galleryId, Title = string.Empty, DateTaken = DateTime.Now, Description = string.Empty }; GalleryPhoto galleryphoto = new GalleryPhoto { OriginalImage = image }; new PhotoLogic().Insert(photo, galleryphoto); }
public async Task<IEnumerable<PhotoDto>> Upload(HttpRequestMessage request) { int galleryId = int.Parse(request.Headers.GetValues("x-galleryId").Single()); var gallery = uow.Galleries.GetAll() .Include(x=>x.GalleryPhotos) .Include("GalleryPhotos.Photo") .Where(x=> x.Id == galleryId).Single(); string workingFolder = System.Web.HttpContext.Current.Server.MapPath("~/Uploads"); var provider = new PhotoMultipartFormDataStreamProvider(workingFolder); await request.Content.ReadAsMultipartAsync(provider); var photos = new List<PhotoDto>(); foreach (var file in provider.FileData) { var fileInfo = new FileInfo(file.LocalFileName); var photo = new Models.Photo(); if (uow.Photos.GetAll().Where(x => x.Name == fileInfo.Name).FirstOrDefault() != null) { photo = uow.Photos.GetAll().Where(x => x.Name == fileInfo.Name).Single(); } else { uow.Photos.Add(photo); } photo.Name = fileInfo.Name; photo.Created = fileInfo.CreationTime; photo.Modified = fileInfo.LastWriteTime; photo.Size = fileInfo.Length / 1024; if(gallery.GalleryPhotos.Where(x=>x.Photo.Name == photo.Name).FirstOrDefault() == null) { var galleryPhoto = new GalleryPhoto(); galleryPhoto.Photo = photo; gallery.GalleryPhotos.Add(galleryPhoto); } uow.SaveChanges(); } return photos; }
public ActionResult AddPhoto(GalleryPhoto galleryPhoto, HttpPostedFileBase image) { var user = db.Users.Find(User.Identity.GetUserId()); var currentChapter = db.Chapters.First(c => c.CurrentChapter == true); if (ImageUploadValidator.IsWebFriendlyImage(image)) { //Counter var num = 0; //Gets Filename without the extension var fileName = Path.GetFileNameWithoutExtension(image.FileName); var gPic = Path.Combine("/GalleryPhotos/", fileName + Path.GetExtension(image.FileName)); //Checks if pPic matches any of the current attachments, //if so it will loop and add a (number) to the end of the filename while (db.GalleryPhotos.Any(p => p.File == gPic)) { //Sets "filename" back to the default value fileName = Path.GetFileNameWithoutExtension(image.FileName); //Add's parentheses after the name with a number ex. filename(4) fileName = string.Format(fileName + "(" + ++num + ")"); //Makes sure pPic gets updated with the new filename so it could check gPic = Path.Combine("/GalleryPhotos/", fileName + Path.GetExtension(image.FileName)); } image.SaveAs(Path.Combine(Server.MapPath("~/GalleryPhotos/"), fileName + Path.GetExtension(image.FileName))); galleryPhoto.File = gPic; db.SaveChanges(); } galleryPhoto.Created = System.DateTime.Now; galleryPhoto.AuthorId = user.Id; galleryPhoto.Published = false; galleryPhoto.Ignored = false; galleryPhoto.ChapterId = currentChapter.Id; db.GalleryPhotos.Add(galleryPhoto); db.SaveChanges(); return(RedirectToAction("ProfilePage", "Home", new { id = User.Identity.GetUserId() })); }
/// <summary> /// Inserts the specified photo. /// </summary> /// <param name="photo">The photo.</param> /// <param name="galleryPhoto">The gallery photo.</param> public void Insert(Photo photo, GalleryPhoto galleryPhoto) { GalleryPhoto adminPhotos = new GalleryPhoto(); GallerySettings settings = GallerySettings.Load(); Bitmap orginalBitmap = ImageConversion.ConvertByteArrayToBitmap(galleryPhoto.OriginalImage); //hardcoded administration image dimensions. This will allow the user to change their image sizes and not have it effect my pretty admin layout. ImageDimension adminThumbnailDimensions = new ImageDimension { Height = 100, Width = 100 }; ImageDimension adminFullsizeDimensions = new ImageDimension { Height = 600, Width = 600 }; adminThumbnailDimensions = FindImagePerspective(orginalBitmap, adminThumbnailDimensions); adminFullsizeDimensions = FindImagePerspective(orginalBitmap, adminFullsizeDimensions); //Resize the Admin images adminPhotos.ThumbnailImage = ImageConversion.Resize(galleryPhoto.OriginalImage, adminThumbnailDimensions); adminPhotos.DisplayImage = ImageConversion.Resize(galleryPhoto.OriginalImage, adminFullsizeDimensions); //calculate the correct dimensions ImageDimension thumbnailDimensions = FindImagePerspective(orginalBitmap, settings.ThumbnailDimensions); ImageDimension fullsizeDimensions = FindImagePerspective(orginalBitmap, settings.FullsizeDimensions); //Resize the images galleryPhoto.ThumbnailImage = ImageConversion.Resize(galleryPhoto.OriginalImage, thumbnailDimensions); galleryPhoto.DisplayImage = ImageConversion.Resize(galleryPhoto.OriginalImage, fullsizeDimensions); //Set photo profile photo.Profile = fullsizeDimensions.PhotoProfile; //Insert new images into the Database _resource.Insert(photo, galleryPhoto, adminPhotos); }
/// <summary> /// Inserts Photo into the Photos Table /// </summary> /// <param name="photo">A new populated photo.</param> /// <param name="galleryPhoto"></param> /// <param name="adminPhotos">Photos to be used in admin section</param> /// <returns>Insert Count</returns> public int Insert(Photo photo, GalleryPhoto galleryPhoto, GalleryPhoto adminPhotos) { return(photoDb.Insert(photo, galleryPhoto, adminPhotos, "Photo_Insert")); }
/// <summary> /// update gallery images /// </summary> /// <param name="photoID">id of the photo entry</param> /// <param name="photos">new versions of the images</param> /// <returns></returns> public int UpdateImages(int photoID, GalleryPhoto photos) { int updateCount = photoDb.UpdateImages(photoID, photos, "Photo_ImagesUpdate"); return(updateCount); }
public void GalleriesEditComplexTest() { Flickr.CacheDisabled = true; Flickr.FlushCache(); string primaryPhotoId = "486875512"; string comment = "You don't get much better than this for the best Entrance to Hell.\n\n" + DateTime.Now.ToString(); string galleryId = "78188-72157622589312064"; Flickr f = TestData.GetAuthInstance(); // Get photos var photos = f.GalleriesGetPhotos(galleryId); List <string> photoIds = new List <string>(); foreach (var p in photos) { photoIds.Add(p.PhotoId); } // Remove the last one. GalleryPhoto photo = photos[photos.Count - 1]; photoIds.Remove(photo.PhotoId); // Update the gallery f.GalleriesEditPhotos(galleryId, primaryPhotoId, photoIds); // Check removed photo no longer returned. var photos2 = f.GalleriesGetPhotos(galleryId); Assert.AreEqual(photos.Count - 1, photos2.Count, "Should be one less photo."); bool found = false; foreach (var p in photos2) { if (p.PhotoId == photo.PhotoId) { found = true; break; } } Assert.IsFalse(false, "Should not have found the photo in the gallery."); // Add photo back in f.GalleriesAddPhoto(galleryId, photo.PhotoId, photo.Comment); var photos3 = f.GalleriesGetPhotos(galleryId); Assert.AreEqual(photos.Count, photos3.Count, "Count should match now photo added back in."); found = false; foreach (var p in photos3) { if (p.PhotoId == photo.PhotoId) { Assert.AreEqual(photo.Comment, p.Comment, "Comment should have been updated."); found = true; break; } } Assert.IsTrue(found, "Should have found the photo in the gallery."); }
public ActionResult Delete(GalleryPhoto photo) { _context.GallerySet.Remove(_context.GallerySet.Find(photo.Id)); _context.SaveChanges(); return(RedirectToAction("Index")); }