public ActionResult EditTags(int? id) { if (!id.HasValue) return RedirectToRoute("Default"); var db = new TagRepository(); var photoDB = new PhotoGalleryRepository(); var tags = db.GetSortedTagListByPhoto(id.Value); var photo = photoDB.GetPhoto(id.Value); if (photo == null) return HttpNotFound(); ViewBag.Title = "Photo Tags - " + photo.FileTitle; var tagsList = new List<string>(); foreach (var tag in tags) { tagsList.Add(tag.TagName); } dynamic model = new ExpandoObject(); model.Photo = photo; model.TagStringToDisplay = String.Join("; ", tagsList.ToArray()); return View("EditTags", model); }
public ActionResult Default() { ViewBag.Title = "Photo Gallery"; var db = new PhotoGalleryRepository(); var galleries = db.GetGalleryList(); return View(galleries); }
public ActionResult List() { var db = new PhotoGalleryRepository(); var galleries = db.GetGalleryList(); var jsonGalleries = galleries.Select(gallery => new jsonGallery { id = gallery.Id, name = gallery.Name }).ToList(); return Json(jsonGalleries, JsonRequestBehavior.AllowGet); }
public ActionResult CommentsForUser() { if (WebSecurity.CurrentUserId <= 0) return Json(new []{ "error", "you must be logged in to use this feature"}, JsonRequestBehavior.AllowGet); var db = new PhotoGalleryRepository(); IList<dynamic> comments = db.GetCommentsByUser(); var jsonComments = comments.Select(comment => new jsonComment { id = comment.Id, date = comment.CommentDate.ToString(), text = comment.CommentText }).ToList(); return Json(jsonComments, JsonRequestBehavior.AllowGet); }
public ActionResult Thumbnail(int id) { var db = new PhotoGalleryRepository(); var gallery = db.GetGallery(id); if (gallery == null) { return HttpNotFound(); } var photos = db.GetTopPhotosForGallery(id); if (photos.Count == 0) { return File(Server.MapPath("~/Content/Images/gallery-empty.png"), "image/jpeg"); } using (var generator = new MultiThumbnailGenerator()) { foreach (var photo in photos) { using (var imageStream = new MemoryStream(photo.FileContents)) { using (var image = System.Drawing.Image.FromStream(imageStream)) { generator.AddImage(image); } } } using (var outStream = new MemoryStream()) { generator.WritePngToStream(outStream); var image = new WebImage(outStream); image.Write(); return null; } } }
public ActionResult New(string Name) { if (Name.IsEmpty()) ModelState.AddModelError("Name", "You must specify a gallery name."); if (ModelState.IsValid) { var db = new PhotoGalleryRepository(); var nameExists = db.GetGalleryCount(Name) > 0; if (nameExists) { ModelState.AddModelError("Name", "A gallery with the supplied name already exists."); } else { int galleryId = db.CreateGallery(Name); return RedirectToAction("View", new { id = galleryId }); } } return View(); }
public ActionResult EditTags(int id, string newTags) { var photoRepository = new PhotoGalleryRepository(); var tagRepository = new TagRepository(); var photo = photoRepository.GetPhoto(id); if (photo == null) return HttpNotFound(); var tagNames = newTags.Split(';'); tagRepository.DeleteTagsForPhoto(id); foreach (string tagName in tagNames) { var trimmed = tagName.Trim(); bool exists = tagRepository.GetTagCount(trimmed) > 0; if (!exists) tagRepository.InsertTag(trimmed); photoRepository.InsertPhotoTag(id, trimmed); } return RedirectToAction("View", "Photo", new { id = id }); }
public ActionResult View(int? id, string newComment) { if (!id.HasValue) return RedirectToRoute("Default"); if (newComment.IsEmpty()) return RedirectToAction("View", new { id = id.Value }); var db = new PhotoGalleryRepository(); db.InsertComment(id.Value, newComment, WebSecurity.CurrentUserId); return RedirectToAction("View", new { id = id.Value }); }
public ActionResult View(int? id) { if (!id.HasValue) return RedirectToRoute("Default"); var photoDB = new PhotoGalleryRepository(); var tagDB = new TagRepository(); var userDB = new UserRepository(); var photo = photoDB.GetPhoto(id.Value); if (photo == null) return HttpNotFound(); ViewBag.Title = "Photo - " + photo.FileTitle; dynamic model = new ExpandoObject(); model.Photo = photo; model.User = userDB.GetUserById(photo.UserId); model.Gallery = photoDB.GetGallery(photo.GalleryId); model.Comments = photoDB.GetCommentsByPhoto(photo.Id); model.TagList = tagDB.GetTagListByPhoto(photo.Id); return View("View", model); }
public ActionResult Thumbnail(int id) { var db = new PhotoGalleryRepository(); var photo = db.GetPhoto(id); if (photo == null) return HttpNotFound(); var size = Request["size"] ?? ""; int width; int height; switch (size.ToUpperInvariant()) { case "": case "SMALL": width = 200; height = 200; break; case "MEDIUM": width = 400; height = 300; break; case "LARGE": width = 625; height = 625; break; default: return new HttpStatusCodeResult(400); } var image = new WebImage(photo.FileContents); image.Resize(width, height).Write(); return null; }
public ActionResult Remove(int id) { var repository = new PhotoGalleryRepository(); var photo = repository.GetPhoto(id); WebSecurity.RequireUser(photo.UserId); repository.RemovePhoto(id); return RedirectToAction("View", "Gallery", new {id = photo.GalleryId}); }
public ActionResult Remove(int? id) { if (!id.HasValue) return RedirectToRoute("Default"); var repository = new PhotoGalleryRepository(); var photo = repository.GetPhoto(id.Value); if (photo == null) return HttpNotFound(); ViewBag.Title = "Remove Photo - " + photo.FileTitle; return View(photo); }
public ActionResult Full(int? id) { if (!id.HasValue) return RedirectToAction("View", new { id = id.Value }); var db = new PhotoGalleryRepository(); var photo = db.GetPhoto(id.Value); if (photo == null) return HttpNotFound(); Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(photo.FileTitle + photo.FileExtension))); new WebImage(photo.FileContents).Write(); return null; }
public ActionResult View(int id) { var db = new PhotoGalleryRepository(); var gallery = db.GetGallery(id); if (gallery == null) return HttpNotFound(); var photos = db.GetPhotosForGallery(id); ViewBag.Title = "Gallery - " + gallery.Name; ViewBag.Name = gallery.Name; ViewBag.GalleryId = id; return View(photos); }
public ActionResult Upload() { var db = new PhotoGalleryRepository(); int id = Request.Url.Segments[3].AsInt(); var numFiles = Request.Files.Count; int imageId = 0; for (int i = 0; i < numFiles; i++) { var file = Request.Files[i]; if (file.ContentLength > 0) { var fileUpload = new WebImage(file.InputStream); var fileTitle = Path.GetFileNameWithoutExtension(file.FileName).Trim(); if (fileTitle.IsEmpty()) { fileTitle = "Untitled"; } var fileExtension = Path.GetExtension(file.FileName).Trim(); var fileBytes = fileUpload.GetBytes(); imageId = db.InsertImage(id, WebSecurity.CurrentUserId, fileTitle, fileExtension, fileUpload.ImageFormat, fileBytes.Length, fileBytes); } } return RedirectToAction("View", "Photo", new { id = imageId }); }
public ActionResult Upload(int id) { WebSecurity.RequireAuthenticatedUser(); var db = new PhotoGalleryRepository(); var gallery = db.GetGallery(id); if (gallery == null) return HttpNotFound(); ViewBag.Title = "Upload Photo to Gallery - " + gallery.Name; return View(gallery); }