Beispiel #1
0
        /// <summary>
        /// Adding a new record to database via EF
        /// </summary>
        /// <param name="inputFileName"></param>
        /// <param name="inputFileContent"></param>
        /// <param name="outputFileName"></param>
        /// <param name="outputFileContent"></param>
        /// <param name="hashInput"></param>
        /// <param name="hashOutput"></param>
        /// <param name="trivia"></param>
        public static void AddNewRecord(string inputFileName, byte[] inputFileContent, string outputFileName, byte[] outputFileContent, string hashInput, string hashOutput, string trivia)
        {

            using (DESEDMEntities context = new DESEDMEntities())
            {
                try
                {
                    context.DESContents.AddObject(new DESContent() { InputFileName = inputFileName, InputFileContent = inputFileContent, OutputFileName = outputFileName, OutputFileContent = outputFileContent, HashInput = hashInput, HashOutput = hashOutput, Trivia = trivia });
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Print database content
 /// </summary>
 public static void PrintAllContent()
 {
     using (DESEDMEntities context = new DESEDMEntities())
     {
         foreach (DESContent c in context.DESContents)
             Console.WriteLine(c.InputFileName);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Remove via link
 /// </summary>
 public static void RemoveRecordWithLINQ()
 {
     using (DESEDMEntities context = new DESEDMEntities())
     {
         // Check whether we have it or not
         var contentToDelete = (from c in context.DESContents where c.Id == 2222 select c).FirstOrDefault();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Update a row via id
        /// </summary>
        private static void UpdateRecord()
        {
            using (DESEDMEntities context = new DESEDMEntities())
            {
                EntityKey key = new EntityKey("DESEDMEntities.DESContents", "Id", 2222);

                DESContent contentToUpdate = (DESContent)context.GetObjectByKey(key);
                Console.WriteLine(contentToUpdate.EntityState);

                if (contentToUpdate != null)
                {
                    contentToUpdate.InputFileName = "Updated.txt";
                    context.SaveChanges();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Remove a row via id
        /// </summary>
        public static void RemoveRecord()
        {
            using (DESEDMEntities context = new DESEDMEntities())
            {
                EntityKey key = new EntityKey("DESEDMEntities.DESContents", "Id", 2222);
                DESContent contentToDelete = (DESContent)context.GetObjectByKey(key);
                if (contentToDelete != null)
                {
                    context.DeleteObject(contentToDelete);
                    context.SaveChanges();
                }

            }
        }