/// <summary>
        /// Deleting report by id.
        /// </summary>
        /// <param name="id">Report ID for deletion.</param>
        /// <returns>Operation status (for future dependencies).</returns>
        public bool DeleteReport(int id)
        {
            using (PhotoCollectionDatabaseEntities context = new PhotoCollectionDatabaseEntities(_connectionString))
            {
                context.SavedReports.DeleteObject((from o in context.SavedReports where o.ID == id select o).First());
                context.SaveChanges();

                return true;
            }
        }
        /// <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 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 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 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 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>
        /// 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>
        /// 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;
            }
        }
Ejemplo n.º 11
0
        /// <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;
        }
Ejemplo n.º 12
0
        /// <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;
        }