/// <summary> /// Get one exif. /// </summary> /// <param name="id">Exif ID.</param> /// <returns>One exif.</returns> public ExifAttribute GetExif(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.ExifAttributes where o.ID == id select o).First()); } }
/// <summary> /// Gets all exif. /// </summary> /// <returns>All exif collection.</returns> public List <ExifAttribute> GetAllExif() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.ExifAttributes select o).ToList()); } }
/// <summary> /// Fills the tags. /// </summary> /// <param name="context">The Context.</param> /// <param name="id">Photo ID.</param> private List <Tag> FillTags(PhotoCollectionDatabaseEntities context, int id) { return((from o in context.Tags join t2p in context.Tags2PhotosSet on o.ID equals t2p.TagID where t2p.PhotoID == id select o).Distinct().ToList()); }
/// <summary> /// Get all reports. /// </summary> /// <returns>Reports list.</returns> public List <SavedReport> GetAllReports() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.SavedReports select o).ToList()); } }
/// <summary> /// Gets all tags. /// </summary> /// <returns>All photos collection.</returns> public List <Tag> GetAllTags() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.Tags select o).ToList()); } }
/// <summary> /// Get all history of reports. /// </summary> /// <returns>Reports history list.</returns> public List <ReportsHistory> GetAllReportsHistory() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.ReportsHistories select o).ToList()); } }
/// <summary> /// Get one photo. /// </summary> /// <param name="id">Photo ID.</param> /// <returns>One photo.</returns> public Photo GetPhoto(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { Photo p = context.Photos.Where(a => a.ID == id).First(); p.Tags = FillTags(context, id); return(p); } }
/// <summary> /// Gets all tags for photo id. /// </summary> /// <param name="photoId">The photo id.</param> /// <returns>All assigned tags to the photo.</returns> public List <Tag> GetTagsForPhoto(int photoId) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { return((from o in context.Tags join p in context.Photos on photoId equals p.ID select o).ToList()); } }
/// <summary> /// Deleting tag by id. /// </summary> /// <param name="id">Tag ID for deletion.</param> /// <returns>Operation status (for future dependencies).</returns> public bool DeleteTag(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { context.Tags.DeleteObject((from o in context.Tags where o.ID == id select o).First()); context.SaveChanges(); return(true); } }
/// <summary> /// Adding new exif into database. /// </summary> /// <param name="newExif">New exif entity.</param> /// <returns>ID for created exif.</returns> public int AddExif(ExifAttribute newExif) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newExif.ID = context.ExifAttributes.NextId(p => p.ID); context.ExifAttributes.AddObject(newExif); context.SaveChanges(); return(newExif.ID); } }
/// <summary> /// Adding new attributes into database. /// </summary> /// <param name="newAttributes">New attribute entity.</param> /// <returns>ID for created attribute.</returns> public int AddAttribute(AdditionalAttribute newAttributes) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newAttributes.ID = context.AdditionalAttributes.NextId(p => p.ID); context.AdditionalAttributes.AddObject(newAttributes); context.SaveChanges(); return(newAttributes.ID); } }
/// <summary> /// Adding new archive into database. /// </summary> /// <param name="newArchive">New archive entity.</param> /// <returns>ID for created archive.</returns> public int AddArchive(Archive newArchive) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newArchive.ID = context.Tags.NextId(p => p.ID); context.Archives.AddObject(newArchive); context.SaveChanges(); return(newArchive.ID); } }
/// <summary> /// Adding new report into database. /// </summary> /// <param name="newReport">New report entity.</param> /// <returns>ID for created report.</returns> public int AddReport(SavedReport newReport) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newReport.ID = context.Tags.NextId(p => p.ID); context.SavedReports.AddObject(newReport); context.SaveChanges(); return(newReport.ID); } }
/// <summary> /// Adding new tag into database. /// </summary> /// <param name="newTag">New tag entity.</param> /// <returns>ID for created tag.</returns> public int AddTag(Tag newTag) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newTag.ID = context.Tags.NextId(p => p.ID); context.Tags.AddObject(newTag); context.SaveChanges(); return(newTag.ID); } }
/// <summary> /// Adding new historical usage of report into database. /// </summary> /// <param name="newHistory">New report's history entity.</param> /// <returns>ID for created history.</returns> public int AddReportHistoricalEntry(ReportsHistory newHistory) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newHistory.ID = context.ReportsHistories.NextId(p => p.ID); context.ReportsHistories.AddObject(newHistory); context.SaveChanges(); return(newHistory.ID); } }
/// <summary> /// Adding photos by group. /// </summary> /// <param name="photos">List of photos.</param> /// <returns>Row count for added group.</returns> public int AddPhotosGroup(List <Photo> photos) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { foreach (Photo each in photos) { each.ID = context.Photos.NextId(p => p.ID); context.Photos.AddObject(each); } return(context.SaveChanges()); } }
/// <summary> /// Adding new photo into database. /// </summary> /// <param name="newPhoto">New photo entity.</param> /// <returns>ID for created photo.</returns> public int AddPhoto(Photo newPhoto) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { newPhoto.ID = context.Photos.NextId(p => p.ID); newPhoto.Date = DateTime.Now; context.Photos.AddObject(newPhoto); context.SaveChanges(); return(newPhoto.ID); } }
/// <summary> /// Gets all photos. /// </summary> /// <returns>All photos collection.</returns> public List <Photo> GetAllPhotos() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { List <Photo> returned = (from o in context.Photos select o).ToList(); foreach (var p in returned) { p.Tags.Clear(); p.Tags = FillTags(context, p.ID); } return(returned); } }
/// <summary> /// Gets the tag. /// </summary> /// <param name="id">The id.</param> /// <returns>Tag entity.</returns> public Tag GetTag(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <Tag> tag = from o in context.Tags where o.ID == id select o; if (tag.Count() != 0) { return(tag.First()); } else { return(null); } } }
/// <summary> /// Get one saved report. /// </summary> /// <param name="id">Report ID.</param> /// <returns>One report.</returns> public SavedReport GetReport(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <SavedReport> report = from o in context.SavedReports where o.ID == id select o; if (report.Count() != 0) { return(report.First()); } else { return(null); } } }
/// <summary> /// Get one archive. /// </summary> /// <param name="id">Archive ID.</param> /// <returns>One Archive.</returns> public Archive GetArchive(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <Archive> archive = from o in context.Archives where o.ID == id select o; if (archive.Count() != 0) { return(archive.First()); } else { return(null); } } }
/// <summary> /// Get one AdditionalAttribute. /// </summary> /// <param name="id">Additional Attribute ID.</param> /// <returns>One AdditionalAttributes entity.</returns> public AdditionalAttribute GetAttribute(int id) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <AdditionalAttribute> attribute = from o in context.AdditionalAttributes where o.ID == id select o; if (attribute.Count() != 0) { return(attribute.First()); } else { return(null); } } }
/// <summary> /// Deleting report history by saved report id. /// </summary> /// <param name="savedReportId">Saved report's ID for deletion.</param> /// <returns>Operation status (for future dependencies).</returns> public bool DeleteReportsHistoryBySavedReportId(int savedReportId) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { foreach (var entry in (from o in context.ReportsHistories join report in context.SavedReports on savedReportId equals report.ID select o)) { context.ReportsHistories.DeleteObject(entry); } context.SaveChanges(); return(true); } }
/// <summary> /// Deleting photos by list of ids. /// </summary> /// <param name="ids">List of ids.</param> /// <returns>Row count number.</returns> public int DeletePhotos(List <int> ids) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { foreach (int id in ids) { foreach (var tag2photo in (from o in context.Tags2PhotosSet where o.PhotoID == id select o)) { context.Tags2PhotosSet.DeleteObject(tag2photo); } context.Photos.DeleteObject((from o in context.Photos where o.ID == id select o).First()); } return(context.SaveChanges()); } }
/// <summary> /// Gets the last photo. /// </summary> /// <returns>Last photo entity.</returns> public Photo GetLastPhoto() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <Photo> query = (from o in context.Photos select o); if (query.Count() == 0) { return(null); } else { Photo p = query.Last(); p.Tags = FillTags(context, p.ID); return(p); } } }
/// <summary> /// Adds the template tag. /// </summary> /// <returns>Sample tag ID.</returns> public int AddTemplateTag() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { Tag tag = new Tag(); tag.ID = context.Tags.NextId(t => t.ID); tag.IconPath = "none"; tag.CreationDate = System.Convert.ToDateTime(System.DateTime.Now); tag.Name = "TemporaryTag"; tag.ParentID = null; context.Tags.AddObject(tag); context.SaveChanges(); return(tag.ID); } }
/// <summary> /// Adds the template archive. /// </summary> /// <returns>Sample archive ID.</returns> public int AddTemplateArchive() { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { Archive archive = new Archive(); archive.ID = context.Archives.NextId(a => a.ID); archive.Capacity = 1048567; archive.IsExternal = false; archive.DeviceID = "007"; archive.HddLetter = "C"; context.Archives.AddObject(archive); context.SaveChanges(); return(archive.ID); } }
/// <summary> /// Get one ExifAttribute by photo ID. /// </summary> /// <param name="photoId">Photo ID.</param> /// <returns>One ExifAttributes entity.</returns> public ExifAttribute GetExifAttributeByPhoto(int photoId) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <ExifAttribute> attribute = from o in context.ExifAttributes join photo in context.Photos on photoId equals photo.ID select o; if (attribute.Count() != 0) { return(attribute.First()); } else { return(null); } } }
/// <summary> /// Get one report history by saved report ID. /// </summary> /// <param name="savedReportId">Saved report ID.</param> /// <returns>One report's history.</returns> public ReportsHistory GetReportHistoryBySavedReportId(int savedReportId) { using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString)) { IEnumerable <ReportsHistory> reportHistory = from o in context.ReportsHistories join report in context.SavedReports on savedReportId equals report.ID select o; if (reportHistory.Count() != 0) { return(reportHistory.First()); } else { return(null); } } }
/// <summary> /// Untaging photo. /// </summary> /// <param name="photoID">Photo ID.</param> /// <param name="tagName">Tag name.</param> /// <returns></returns> public static bool UntagPhoto(int photoID, String tagName) { string connectionString = ConnectionStringHelper.GetActualConnectionString(); // Updates collections. using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(connectionString)) { Photo resultPhoto = context.Photos.Where(p => p.ID == photoID).First(); Tag resultTag = context.Tags.Where(t => t.Name == tagName).First(); if (resultPhoto != null && resultTag != null) { context.Tags2PhotosSet.DeleteObject((from o in context.Tags2PhotosSet where o.PhotoID == resultPhoto.ID && o.TagID == resultTag.ID select o).First()); context.SaveChanges(); } } return(true); }