コード例 #1
0
 /* Method adds application to the context */
 public void Add(Application application)
 {
     _ctx.Add(application);
     _ctx.SaveChanges();
 }
コード例 #2
0
        private static PGAContext GetContextWithData()
        {
            /* Initialize an in-memory Db context, we are not using the context linked to the
             * SQL server as that falls under integration tests */

            var options = new DbContextOptionsBuilder <PGAContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new PGAContext(options);


            /* Add seed data to in-memory context */
            Programme programme1 = new Programme()
            {
                Id = 1, ProgrammeName = "Masters by reasearch"
            };
            Programme programme2 = new Programme()
            {
                Id = 2, ProgrammeName = "Masters by course work"
            };

            context.Add(programme1);
            context.Add(programme2);

            Position position1 = new Position()
            {
                Id = 1, PositionName = "Supervisor"
            };
            Position position2 = new Position()
            {
                Id = 2, PositionName = "PGO"
            };
            Position position3 = new Position()
            {
                Id = 3, PositionName = "PGC"
            };

            context.Add(position1);
            context.Add(position2);
            context.Add(position3);

            Users supervisor = new Users()
            {
                Id = 1, FirstName = "Fred", Position = position1
            };

            context.Add(supervisor);


            Application application = new Application()
            {
                Id         = 1,
                FirstName  = "Jon",
                LastName   = "Doe",
                Programme  = programme1,
                Supervisor = supervisor
            };

            context.Add(application);

            ApplicationFiles file1 = new ApplicationFiles()
            {
                Application = application, Id = 1, Title = "FirstDoc"
            };
            ApplicationFiles file2 = new ApplicationFiles()
            {
                Application = application, Id = 2, Title = "SecondDoc"
            };

            context.Add(file1);
            context.Add(file2);


            List <ApplicationFiles> docs = new List <ApplicationFiles>(new ApplicationFiles[] { file1, file2 });

            application.ApplicationFiles = docs;

            context.SaveChanges();


            return(context);
        }