/**** ALBUM ****/ public void InsertAlbumComment(Guid albumId, Comment newComment) { using (var context = new GalleryContext()) { var album = context.Albums.Where(p => p.AlbumId == albumId).FirstOrDefault(); album.Comments.Add(newComment); context.SaveChanges(); } }
public void InsertImageComment(Guid imgID, Comment newComment) { using (var context = new GalleryContext()) { var image = context.Images.Where(p => p.ImageId == imgID).FirstOrDefault(); image.Comments.Add(newComment); context.SaveChanges(); } }
public void Delete(Guid id) { using (var ctx = new GalleryContext()) { var commetntoDelete = ctx.Comments.Find(id); ctx.Comments.Remove(commetntoDelete); ctx.SaveChanges(); } }
public ActionResult Create([Bind(Include = "ID,Title,AlbumId")] Photo photo, HttpPostedFileBase file) { if (ModelState.IsValid) { try { TempData["Message"] = ""; var filename = ""; if (file != null && file.ContentLength > 0) { Guid gid; gid = Guid.NewGuid(); var extension = Path.GetExtension(file.FileName); filename = gid + extension; var path = Path.Combine(Server.MapPath("~/Content/PhotoGallery/" + setAlbumName(photo.AlbumId)), filename); var data = new byte[file.ContentLength]; file.InputStream.Read(data, 0, file.ContentLength); using (var sw = new FileStream(path, FileMode.Create)) { sw.Write(data, 0, data.Length); } } photo.ImageName = filename; photo.InsertedDateTime = DateTime.Now; photo.InsertedBy = User.Identity.Name; db.Photos.Add(photo); db.SaveChanges(); TempData["Message"] = "<div class='alert alert-success'><a href='#' class='close' data-dismiss='alert'>×</a><strong>Success!</strong> Successfully Save.</div> "; } catch (Exception ex) { TempData["Message"] = "<div class='alert alert-danger'><a href='#' class='close' data-dismiss='alert'>× Directory</a><strong> " + ex.ToString() + "</strong> Not found.</div>"; } return(RedirectToAction("Index")); } ViewBag.AlbumId = new SelectList(db.ImageGalleries, "ID", "AlbumName", photo.AlbumId); return(View(photo)); }
public void UpdateImage(Image img) { using (var context = new GalleryContext()) { var image = context.Images.Where(p => p.ImageId == img.ImageId).FirstOrDefault(); image.Title = img.Title; image.Description = img.Description; //image.CreateDate = img.CreateDate; context.SaveChanges(); } }
public void UpdateAlbum(Album alb) { using (var context = new GalleryContext()) { var album = context.Albums.Where(p => p.AlbumId == alb.AlbumId).FirstOrDefault(); album.AlbumName = alb.AlbumName; //album.AlbumComment = alb.AlbumComment; //album.CreateDate = alb.CreateDate; context.SaveChanges(); } }
public void UpdateUser(GalleryUser person) { using (var context = new GalleryContext()) { var user = context.Users.Where(p => p.Id == person.Id).FirstOrDefault(); user.FullName = person.FullName; user.Email = person.Email; user.Password = person.Password; user.UserName = person.UserName; context.SaveChanges(); } }
public bool Register(UserLoginModel userloginmodel) { UserLogin ulogin = new UserLogin() { Username = userloginmodel.UName, Password = Sha256.ComputeSha256Hash(userloginmodel.Password) }; UserInformation uInfo = new UserInformation() { Uage = userloginmodel.Uage, Uname = userloginmodel.Name, Umail = userloginmodel.Umail, Uprofession = userloginmodel.Uprofession, Urole = "admin" }; uInfo.UserLogin = ulogin; gc.UserInformations.Add(uInfo); gc.SaveChanges(); return(true); }
public virtual ActionResult Post(FormCollection data, string vsixId) { var rating = GetRating(data); using (var ctx = new GalleryContext()) { var extension = ctx.ExtensionsWithStuff.First(e => e.VsixId == vsixId); extension.AddRating(rating); ctx.SaveChanges(); } return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name)); }
public void Delete(Guid id) { using (var ctx = new GalleryContext()) { var itemToDelete = ctx.Photos.FirstOrDefault(x => x.Id == id); var commetnsToDelete = ctx.Comments.Where(x => x.PhotoRefID == id); ctx.Comments.RemoveRange(commetnsToDelete); ctx.Photos.Remove(itemToDelete); ctx.SaveChanges(); } }
// GET: Photo public ActionResult AlbumList() { using (var context = new GalleryContext()) { var NewAlbum = new AlbumClass(); NewAlbum.AlbumID = Guid.NewGuid(); NewAlbum.AlbumName = "wowowowow"; context.album.Add(NewAlbum); context.SaveChanges(); } return(View(db.album.ToList())); }
public IActionResult Post([FromBody] PhotoTag ptag) { string userId = ControllerUtility.GetUserID(this._httpContextAccessor); if (userId == null) { return(StatusCode(401)); } this._context.PhotoTags.Add(ptag); _context.SaveChanges(); return(Created(ptag)); }
public void UpdateURLsInImages() { GalleryContext db = new GalleryContext(); foreach (var img in db.Images) { img.UrlPath = "~/GalleryImages/" + Path.GetFileName(img.Filename); foreach (var thumb in img.ProcessedImages) { thumb.UrlPath = "~/GalleryImages/" + Path.GetFileName(thumb.Filename); } } db.SaveChanges(); }
public IActionResult ChangeAccessCode(int key, ODataActionParameters paras) { String userId = ControllerUtility.GetUserID(this._httpContextAccessor); if (userId == null) { return(StatusCode(401)); } var album = _context.Albums.FirstOrDefault(c => c.Id == key); if (album == null) { return(NotFound()); } if (String.CompareOrdinal(album.CreatedBy, userId) != 0) { return(StatusCode(401)); } var AccessCode = (string)paras["AccessCode"]; if (string.IsNullOrEmpty(AccessCode)) { album.AccessCodeHint = null; } else { album.AccessCodeHint = AccessCode; } _context.Attach(album); _context.SaveChanges(); return(Ok(true)); }
public HttpResponseMessage Get(string vsixId) { using (var ctx = new GalleryContext()) { var extension = ctx.GetExtensionByVsixId(vsixId); if (extension == null) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } extension.IncreaseDownloadCount(); ctx.SaveChanges(); return(new DownloadExtensionResponseMessage(extension)); } }
public void AddOrUpdate(Album album) { using (var ctx = new GalleryContext()) { var entityToAddORUpdate = ctx.Albums.FirstOrDefault(x => x.Id == album.Id) ?? new Album() { Id = album.Id, UserEmail = album.UserEmail }; entityToAddORUpdate.Name = album.Name; ctx.Albums.AddOrUpdate(entityToAddORUpdate); ctx.SaveChanges(); } }
public ActionResult Create(Photo photo, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(photo)); } if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please choose a file"; return(View(photo)); } var model = new Photo(); foreach (var file in files) { if (file.ContentLength == 0) { continue; } model.Description = photo.Description; model.PhotoId = ++idCounter; var fileName = Guid.NewGuid().ToString(); var extension = Path.GetExtension(file.FileName).ToLower(); using (var img = Image.FromStream(file.InputStream)) { model.ThumbPath = String.Format("/GalleryImages/thumbs/{0}{1}", fileName, extension); model.ImagePath = String.Format("/GalleryImages/{0}{1}", fileName, extension); // Save thumbnail size image, 100 x 100 SaveToFolder(img, fileName, extension, new Size(100, 100), model.ThumbPath); // Save large size image, 800 x 800 SaveToFolder(img, fileName, extension, new Size(600, 600), model.ImagePath); } // Save record to database model.CreatedOn = DateTime.Now; db.Photos.Add(model); db.SaveChanges(); } return(RedirectPermanent("/home")); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new GalleryContext()) { var user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.Users.Add(new User { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public IActionResult Delete(int AlbumID, string PhotoID) { // Delete code here var entry = _context.AlbumPhotos.Find(AlbumID, PhotoID); if (entry == null) { return(NotFound()); } string userId = ControllerUtility.GetUserID(this._httpContextAccessor); if (userId == null) { return(StatusCode(401)); } _context.AlbumPhotos.Remove(entry); _context.SaveChanges(); return(Ok()); }
public void AddOrUppdate(Comment comment) { using (var ctx = new GalleryContext()) { var entityToAddORUpdate = ctx.Comments.FirstOrDefault(x => x.Id == comment.Id) ?? new Comment() { Id = comment.Id, UserEmail = comment.UserEmail }; if (!string.IsNullOrEmpty(comment.Text)) { entityToAddORUpdate.AlbumRefID = (comment.AlbumRefID != Guid.Empty) ? comment.AlbumRefID : null; entityToAddORUpdate.PhotoRefID = (comment.PhotoRefID != Guid.Empty) ? comment.PhotoRefID : null; entityToAddORUpdate.Text = comment.Text; ctx.Comments.AddOrUpdate(entityToAddORUpdate); ctx.SaveChanges(); } } }
public void Delete(Guid Id) { using (var ctx = new GalleryContext()) { var entityToDelete = ctx.Albums.Find(Id); var commetnsToDelete = ctx.Comments.Where(x => x.AlbumRefID == Id).ToList(); var picturesToDelete = ctx.Photos.Where(x => x.AlbumRefID == Id); foreach (var picture in picturesToDelete) { var deleteMe = ctx.Comments.Where(x => x.PhotoRefID == picture.Id); commetnsToDelete.AddRange(deleteMe); } ctx.Comments.RemoveRange(commetnsToDelete); ctx.Photos.RemoveRange(picturesToDelete); ctx.Albums.Remove(entityToDelete); ctx.SaveChanges(); } }
public void InsertImage(Image img, Guid albumId) { using (var context = new GalleryContext()) { context.Images.Add(img); context.AlbumImages.Add(new AlbumImage() { AlbumId = albumId, ImageId = img.ImageId }); if (!IsAlbumSpecial(albumId)) { var albumAllImg = context.Albums.Where(a => a.AlbumName == "All images").FirstOrDefault(); if (albumAllImg != null) { context.AlbumImages.Add(new AlbumImage() { AlbumId = albumAllImg.AlbumId, ImageId = img.ImageId }); } } context.SaveChanges(); } }
private void SeedData(GalleryContext context) { var userId = TestUser.Id; var album1 = new Album { Name = "album1", Description = "desc1", Created = DateTime.Now.AddDays(-1), Updated = DateTime.Now, UserId = userId, }; var album2 = new Album { Name = "album2", Description = "desc2", Created = DateTime.Now.AddDays(-1), Updated = DateTime.Now, UserId = userId, }; var photo1 = new Photo { Name = "photo1", Path = "path", Created = DateTime.Now, Album = album1 }; var photo2 = new Photo { Name = "photo2", Path = "path", Created = DateTime.Now, Album = album1 }; var photo3 = new Photo { Name = "photo3", Path = "path", Created = DateTime.Now, Album = album2 }; var comment1 = new Comment { Text = "comment1", UserId = userId, Photo = photo1 }; var comment2 = new Comment { Text = "comment2", UserId = userId, Photo = photo1 }; var comment3 = new Comment { Text = "comment3", UserId = userId, Photo = photo1 }; context.AddRange(new Album[] { album1, album2 }); context.AddRange(new Photo[] { photo1, photo2, photo3 }); context.AddRange(new Comment[] { comment1, comment2, comment3 }); context.SaveChanges(); }
public void GenerateMissingThumbs() { GalleryContext db = new GalleryContext(); var originals = from oi in db.Images.Include("ProcessedImages") where oi is OriginalImage select oi; // if I do not do this (var origList = originals.ToArray()), I get the following exception when I execute AddThumbs below: // "There is already an open DataReader associated with this Command which must be closed first." var origList = originals.ToArray(); var thumbs = from th in db.Thumbnails select th; var thumbList = thumbs.ToList(); foreach (OriginalImage orig in origList) { if (File.Exists(orig.Filename)) { orig.AddThumbs(thumbList); } else { // file does not exist, so remove from database db.Images.Remove(orig); } } db.SaveChanges(); }
public bool Save() { return(_context.SaveChanges() >= 0); }
public void Upload(Photos photo) { photo.CreatedOn = DateTime.Now; db.Photos.Add(photo); db.SaveChanges(); }
public bool AddArtist(Artist artist) { gc.Add(artist); gc.SaveChanges(); return(true); }
public static void CreateTestingData(GalleryContext context) { // Albums context.Albums.Add(new Album { Id = 1, Title = "Album 1", IsPublic = true, Desp = "Album Desp 1", CreatedBy = DataSetupUtility.UserA, }); context.Albums.Add(new Album { Id = 2, Title = "Album 2", IsPublic = false, Desp = "Album Desp 2", CreatedBy = DataSetupUtility.UserA, }); context.Albums.Add(new Album { Id = 11, Title = "Album 11", IsPublic = false, Desp = "Album Desp 11", CreatedBy = DataSetupUtility.UserB, }); context.SaveChanges(); // Photos var photoid1 = Guid.NewGuid().ToString(); context.Photos.Add(new Photo { PhotoId = photoid1, Title = "Photo A1001", Width = 100, Height = 100, IsPublic = false, FileUrl = "photoa1001", Tags = new List <PhotoTag>() { new PhotoTag { PhotoID = photoid1, TagString = "A1001" } }, }); var photoid2 = Guid.NewGuid().ToString(); context.Photos.Add(new Photo { PhotoId = photoid2, Title = "Photo A1002", Width = 100, Height = 100, IsPublic = false, FileUrl = "photoa1002", }); var photoid3 = Guid.NewGuid().ToString(); context.Photos.Add(new Photo { PhotoId = photoid3, Title = "Photo A2001", Width = 100, Height = 100, IsPublic = false, FileUrl = "photoa2001", }); var photoid4 = Guid.NewGuid().ToString(); context.Photos.Add(new Photo { PhotoId = photoid4, Title = "Photo A2002", Width = 100, Height = 100, IsPublic = false, FileUrl = "photoa2002", }); context.SaveChanges(); // Album phtoos context.AlbumPhotos.Add(new AlbumPhoto { AlbumID = 1, PhotoID = photoid1, }); context.AlbumPhotos.Add(new AlbumPhoto { AlbumID = 1, PhotoID = photoid2, }); context.AlbumPhotos.Add(new AlbumPhoto { AlbumID = 2, PhotoID = photoid3, }); context.AlbumPhotos.Add(new AlbumPhoto { AlbumID = 2, PhotoID = photoid4, }); // User Detail context.UserDetails.Add(new UserDetail { UserID = UserA, DisplayAs = "User A", }); context.UserDetails.Add(new UserDetail { UserID = UserB, DisplayAs = "User B", }); context.SaveChanges(); }
public bool AddArtWork(ArtWork artwork) { gc.Add(artwork); gc.SaveChanges(); return(true); }
public ActionResult Create(Photo photo, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(photo)); } if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please choose a file"; return(View(photo)); } var model = new Photo(); foreach (var file in files) { if (file.ContentLength == 0) { continue; } model.Description = photo.Description; var fileName = Guid.NewGuid().ToString(); var extension = System.IO.Path.GetExtension(file.FileName).ToLower(); using (var img = System.Drawing.Image.FromStream(file.InputStream)) { model.ThumbPath = $@"/GalleryImages//thumbs/{fileName}{extension}"; model.ImagePath = $@"/GalleryImages/{fileName}{extension}"; //CloudBlob blob = cloudBlobContainer.GetBlobReference(model.ThumbPath); //blob.DownloadToFile(model.ThumbPath,FileMode.Create); //blob = cloudBlobContainer.GetBlobReference(model.ImagePath); //blob.DownloadToFile(model.ImagePath,FileMode.Create); //var imageBlob = cloudBlobContainer.GetBlockBlobReference(model.ThumbPath); //imageBlob.UploadFromStreamAsync(file.InputStream); //imageBlob = cloudBlobContainer.GetBlockBlobReference(model.ImagePath); //imageBlob.UploadFromStreamAsync(file.InputStream); //CloudBlockBlob blockBlobImage = cloudBlobContainer.GetBlockBlobReference(model.ImagePath); //using (var fileStream = System.IO.File.OpenRead(model.ImagePath)) //{ // blockBlobImage.UploadFromStream(fileStream); //} // Save thumbnail size image, 100 x 100 model.ThumbPath = SaveToFolder(img, fileName, extension, new Size(200, 200), model.ThumbPath); // Save large size image, 800 x 800 model.ImagePath = SaveToFolder(img, fileName, extension, new Size(800, 800), model.ImagePath); } // Save record to database model.CreatedOn = DateTime.Now; db.Photos.Add(model); db.SaveChanges(); } return(RedirectPermanent("/home")); }