public static string GetUserName(Guid id) { using (var db = new GalleryEntities()) { return(db.Users.Single(x => x.Id == id).Name); } }
public static List <Album> GetAlbumsByUserId(Guid id) { using (var db = new GalleryEntities()) { return(db.Albums.Where(x => x.UserId == id).ToList()); } }
public IEnumerable <Photo> GetItems() { using (var db = new GalleryEntities()) { return(db.Photos.Include("Comments").Include("Album").Include("User").ToList()); } }
public static Guid GetUserId(string name) { using (var db = new GalleryEntities()) { return(db.Users.Single(x => x.Name == name).Id); } }
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 User GetUserByCredentials(string email, string password) { using (var db = new GalleryEntities()) { return(db.Users.FirstOrDefault(x => x.Email == email && x.Password == password)); } }
public IEnumerable <Album> GetItems() { using (var db = new GalleryEntities()) { return(db.Albums.Include("User").Include("Photos").ToList()); } }
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(Album item) { using (var db = new GalleryEntities()) { db.Albums.Add(item); db.SaveChanges(); } }
public void Add(Photo item) { using (var db = new GalleryEntities()) { db.Photos.Add(item); db.SaveChanges(); } }
public Photo FindById(Guid id) { using (var db = new GalleryEntities()) { var photo = db.Photos.Include("User").Include("Comments").Include("Album").FirstOrDefault(x => x.Id == id); photo.Comments = db.Comments.Include("User").Where(x => x.PhotoId == photo.Id).ToList(); return(photo); } }
public ActionResult DeleteComment(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new GalleryEntities()) { var comment = db.Comments.Include(i => i.Photo).FirstOrDefault(x => x.Id == id); return(comment == null ? (ActionResult)HttpNotFound() : View(comment)); } }
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 ActionResult ListUsers() { var users = new List <UserViewModel>(); using (var db = new GalleryEntities()) { db.Users.ToList().ForEach(x => users.Add(new UserViewModel { Id = x.Id, Name = x.Name, Email = x.Email, })); } return(PartialView(users)); }
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(); } }
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 Album FindById(Guid id) { using (var db = new GalleryEntities()) { var album = db.Albums.Include("User").Include("Photos").FirstOrDefault(x => x.Id == id); if (album != null) { album.Photos = db.Photos.Include("User") .Include("Album") .Include("Comments") .Where(x => x.AlbumId == album.Id) .ToList(); } return(album); } }
public Photo GetLastUploadedPhoto() { using (var db = new GalleryEntities()) { var photo = db.Photos.Include("User") .Include("Comments") .Include("Album") .OrderByDescending(x => x.DateAdded) .FirstOrDefault(); if (photo != null) { photo.Comments = db.Comments.Include("User").Where(x => x.PhotoId == photo.Id).ToList(); } return(photo); } }
public ActionResult Index() { using (var db = new GalleryEntities()) { var data = new IndexViewModel(); db.Albums.ToList().ForEach(x => data.AlbumViewModels.Add(new AlbumViewModel { Id = x.Id, Name = x.Name, })); db.Comments.Include("User").Include("Photo").ToList().ForEach(x => data.CommentViewModels.Add(new CommentViewModel { Id = x.Id, Commenter = x.User.Name, Comment = x.Text, Date = x.Date, PhotoName = x.Photo.Name })); db.Photos.Include("User").Include("Album").ToList().ForEach(x => data.PhotoViewModels.Add(new PhotoViewModel { Id = x.Id, Name = x.Name, FileName = x.FileName, Album = x.Album.Name, Uploader = x.User.Name, Description = x.Description, DateAdded = x.DateAdded })); db.Users.ToList().ForEach(x => data.UserViewModels.Add(new UserViewModel { Id = x.Id, Name = x.Name, Email = x.Email, })); return(View(data)); } }
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"); } }