/// <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 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 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 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 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 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 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 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> /// 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> /// 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> /// 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> /// 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); }
/// <summary> /// Adding a tag into tag callection of a photo database. /// </summary> /// <param name="photoID">Id of a photo that is being tagged.</param> /// <param name="tagName">Name od tag.</param> /// <returns>Operation's status.</returns> public static bool TagPhoto(int photoID, String tagName) { // Updates collection. string connectionString = ConnectionStringHelper.GetActualConnectionString(); 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.AddObject(new Tags2Photos() { PhotoID = resultPhoto.ID, TagID = resultTag.ID }); context.SaveChanges(); } } return(true); }