public bool create(Photo photo) { using (PhotoDBEntities pdbe = new PhotoDBEntities()) { try { PhotoEntity pe = new PhotoEntity(); pe.Title = photo.Title; pe.Image = photo.Image; pe.UserName = photo.UserName; pe.AddDate=photo.AddDate; pe.Model=photo.Model; pe.Resolution=photo.Resolution; pe.Explosure=photo.Explosure; pe.CreateDate=photo.CreateDate; pe.Rating = photo.Rating; pe.NumderVote = photo.NumderVote; pdbe.PhotoEntities.Add(pe); pdbe.SaveChanges(); return true; } catch { return false; } }; }
public bool edit(Photo photo) { using (PhotoDBEntities pdbe = new PhotoDBEntities()) { try { PhotoEntity pe = pdbe.PhotoEntities.Single(p => p.Id == photo.Id); pe.Title = photo.Title; pdbe.SaveChanges(); return true; } catch { return false; } } }
public bool delete(Photo photo) { using (PhotoDBEntities pdbe = new PhotoDBEntities()) { try { PhotoEntity pe = pdbe.PhotoEntities.Single(p => p.Id == photo.Id); pdbe.PhotoEntities.Remove(pe); pdbe.SaveChanges(); return true; } catch { return false; } } }
public Photo find(string id) { using (PhotoDBEntities pdbe = new PhotoDBEntities()) { int nid = Convert.ToInt32(id); return pdbe.PhotoEntities.Where(pe => pe.Id == nid).Select(pe => new Photo { Id = pe.Id, Title = pe.Title, Image = pe.Image, UserName = pe.UserName, AddDate = pe.AddDate, Model = pe.Model, Resolution = pe.Resolution, Explosure = pe.Explosure, CreateDate = pe.CreateDate, Rating = pe.Rating, NumderVote = pe.NumderVote }).First(); }; }
public List<Photo> finduser(string name) { using (PhotoDBEntities pdbe = new PhotoDBEntities()) { return pdbe.PhotoEntities.Where(pe => pe.UserName.Equals(name)).Select(pe => new Photo { Id = pe.Id, Title = pe.Title, Image = pe.Image, UserName = pe.UserName, AddDate = pe.AddDate, Model = pe.Model, Resolution = pe.Resolution, Explosure = pe.Explosure, CreateDate = pe.CreateDate, Rating = pe.Rating, NumderVote = pe.NumderVote }).ToList(); }; }