public ActionResult UpdateImageRating(int imageId, double rating, int userId, int albumId) { if (galleryContext.Votes.Count(vote => vote.userId == userId && vote.imageId == imageId) == 0) { galleryContext.Votes.Add(new Votes { imageId = imageId, rating = rating, userId = userId }); } else { var updateVote = galleryContext.Votes.First(vote => vote.userId == userId && vote.imageId == imageId); updateVote.rating = rating; galleryContext.Entry(updateVote).State = EntityState.Modified; } var album = galleryContext.Albums.Find(albumId); album.rating = album.Images.Sum(image => image.Votes.Sum(vote => vote.rating)) / album.Images.Count; galleryContext.Entry(album).State = EntityState.Modified; galleryContext.SaveChanges(); return(Json(new { success = true, newRating = LoadImageRating(imageId) })); }
protected void btnPostComment_Click(object sender, EventArgs e) { var divtimespan = Master.FindControl("divtimespan") as HtmlGenericControl; Stopwatch sw = new Stopwatch(); sw.Start(); string photoIdstring = Request["photoId"]; int photoId = -1; if (!int.TryParse(photoIdstring, out photoId)) { return; } using (GalleryEntities ge = new GalleryEntities()) { Comments c = new Comments(); c.photoId = photoId; c.name = tbName.Text; c.text = tbComment.Text; ge.AddToComments(c); ge.SaveChanges(); } ListView1.DataBind(); sw.Stop(); if (divtimespan != null) { divtimespan.InnerText = string.Format("Elapsed time: {0}", sw.Elapsed); } }
public void Add(Album item) { using (var db = new GalleryEntities()) { db.Albums.Add(item); db.SaveChanges(); } }
protected void uploadButton_Click(object sender, EventArgs e) { var divtimespan = Master.FindControl("divtimespan") as HtmlGenericControl; Stopwatch sw = new Stopwatch(); sw.Start(); //get input data DateTime now = DateTime.Now; string title = tbTitle.Text; string fileName = FileUpload1.FileName; string ext = Path.GetExtension(fileName); byte[] file = FileUpload1.FileBytes; using (var input = new MemoryStream(file)) { //watermarking image var output = new MemoryStream(); AddWaterMark(input, now.ToString(), output); file = new byte[output.Length]; output.Position = 0; BinaryReader br = new BinaryReader(output); file = br.ReadBytes((int)output.Length); br.Close(); } //save image to disk and database string path = Server.MapPath("Images"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } fileName = Guid.NewGuid().GetHashCode().ToString("x") + ext; path = path + "\\" + fileName; try { var ge = new GalleryEntities(); Photos photo = new Photos(); photo.fileName = fileName; photo.postingDate = DateTime.Now; photo.title = title; using (var fs = new FileStream(path, FileMode.Create)) { BinaryWriter bw = new BinaryWriter(fs); bw.Write(file); } ge.AddToPhotos(photo); ge.SaveChanges(); } finally { } ListView_Photos.DataBind(); sw.Stop(); if (divtimespan != null) { divtimespan.InnerText = string.Format("Elapsed time: {0}", sw.Elapsed); } }
public void Add(Photo item) { using (var db = new GalleryEntities()) { db.Photos.Add(item); db.SaveChanges(); } }
public ActionResult DeleteCommentConfirmed(Guid id) { using (var db = new GalleryEntities()) { var comment = db.Comments.Include(i => i.Photo).FirstOrDefault(x => x.Id == id); db.Comments.Remove(comment); db.SaveChanges(); return(RedirectToAction("Index")); } }
public void Add(Comment item) { using (var db = new GalleryEntities()) { db.Comments.Add(new Comment { Id = item.Id, Text = item.Text, Date = item.Date, PhotoId = item.PhotoId, UserId = item.UserId }); db.SaveChanges(); } }
public void Add(User item) { using (var db = new GalleryEntities()) { db.Users.Add(new User { Id = item.Id, Email = item.Email, Name = item.Name, Password = item.Password, Admin = false }); db.SaveChanges(); } }
protected void Button1_Click1(object sender, EventArgs e) { if (FileUpload1.HasFile) { string virtualFolder = "~/GData/"; string physicalFolder = Server.MapPath(virtualFolder); string fileName = Guid.NewGuid().ToString(); string extension = System.IO.Path.GetExtension(FileUpload1.FileName); FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension)); string finalUrl = virtualFolder + fileName + extension; using (GalleryEntities myEntities = new GalleryEntities()) { GalleryModel.Gallery myGallery = new GalleryModel.Gallery(); myGallery.Url = finalUrl; myEntities.AddToGalleries(myGallery); myEntities.SaveChanges(); } Response.Redirect("Galary.aspx"); } }