예제 #1
0
        static async Task Delete()
        {
            using (var db = new MyDbContext())
            {
                var source = new Source
                {
                    Name = "System B"
                };

                db.Sources.Add(source);

                var transaction = new Transaction
                {
                    Source  = source,
                    SysTime = DateTime.UtcNow,
                    User    = "******"
                };

                using (var dbTransaction = await db.BeginTransactionAsync(transaction))
                {
                    var user = db.Users.FirstOrDefault(a => a.Name == userName);

                    db.Users.Remove(user);

                    await db.SaveChangesAsync();

                    dbTransaction.Commit();
                }
            }
        }
예제 #2
0
        static async Task UpdateGarysWorkingComputer()
        {
            using var db = new MyDbContext();
            var source = new Source
            {
                Name = "Tom"
            };

            db.Sources.Add(source);

            var transaction = new Transaction
            {
                Source  = source,
                SysTime = DateTime.UtcNow,
                User    = "******"
            };

            using var dbTransaction = await db.BeginTransactionAsync(transaction);

            var processor = new Processor {
                Name = "AMD A8-7680 OEM"
            };
            var motherBoard = new MotherBoard {
                Name = "ASRock FM2A68M-HD+"
            };
            var videoCard = new VideoCard {
                Name = "MSI AMD Radeon R7 240 LP [R7 240 2GD3 64bit LP]"
            };
            var ram1 = new RAM {
                Name = "Kingston ValueRAM [KVR16N11S8/4]"
            };
            var ram2 = new RAM {
                Name = "Kingston ValueRAM [KVR16N11S8/4]"
            };
            var soundCard = new SoundCard {
                Name = "ORICO SC2-BK"
            };

            db.Processors.Add(processor);
            db.MotherBoards.Add(motherBoard);
            db.VideoCards.Add(videoCard);
            db.RAMs.Add(ram1);
            db.RAMs.Add(ram2);
            db.SoundCards.Add(soundCard);
            await db.SaveChangesAsync();

            var workComputer = (await db.Users.Include(a => a.WorkComputer).FirstAsync(a => a.Name == GaryName)).WorkComputer;

            workComputer.Processor   = processor;
            workComputer.MotherBoard = motherBoard;
            workComputer.VideoCard   = videoCard;
            workComputer.RAM1        = ram1;
            workComputer.RAM2        = ram2;
            workComputer.SoundCard   = soundCard;

            await db.SaveChangesAsync();

            dbTransaction.Commit();
        }
예제 #3
0
        static async Task Add()
        {
            using (var db = new MyDbContext())
            {
                var source = new Source
                {
                    Name = "System A"
                };

                db.Sources.Add(source);

                var transaction = new Transaction
                {
                    Source  = source,
                    SysTime = DateTime.UtcNow,
                    User    = "******"
                };

                using (var dbTransaction = await db.BeginTransactionAsync(transaction))
                {
                    var book1 = new Book
                    {
                        Name = "CLR via C#"
                    };

                    db.Books.Add(book1);

                    var book2 = new Book
                    {
                        Name = "The Art of Computer Programming"
                    };

                    db.Books.Add(book2);

                    var user = new User
                    {
                        ApplTime  = DateTime.UtcNow,
                        BirthDate = DateTime.UtcNow.AddYears(-30),
                        Book1     = book1,
                        Book2     = book2,
                        Name      = userName,
                        Email     = "*****@*****.**",
                        Height    = 180
                    };

                    db.Users.Add(user);

                    await db.SaveChangesAsync();

                    dbTransaction.Commit();
                }
            }
        }
예제 #4
0
        static async Task Update()
        {
            using (var db = new MyDbContext())
            {
                var source = new Source
                {
                    Name = "System B"
                };

                db.Sources.Add(source);

                var transaction = new Transaction
                {
                    Source  = source,
                    SysTime = DateTime.UtcNow,
                    User    = "******"
                };

                using (var dbTransaction = await db.BeginTransactionAsync(transaction))
                {
                    var book1 = new Book
                    {
                        Name = "War and Peace"
                    };

                    var user = db.Users.FirstOrDefault(a => a.Name == userName);

                    user.ApplTime = DateTime.UtcNow;
                    user.Book1    = book1;
                    user.Email    = "*****@*****.**";
                    user.Height   = 181;

                    await db.SaveChangesAsync();

                    dbTransaction.Commit();
                }
            }
        }
예제 #5
0
        static async Task GiveTomWorkingComputer()
        {
            using var db = new MyDbContext();
            var source = new Source
            {
                Name = "Company A"
            };

            db.Sources.Add(source);

            var transaction = new Transaction
            {
                Source  = source,
                SysTime = DateTime.UtcNow,
                User    = "******"
            };

            using var dbTransaction = await db.BeginTransactionAsync(transaction);

            var processor = new Processor {
                Name = "AMD Athlon X4 840 OEM"
            };
            var motherBoard = new MotherBoard {
                Name = "MSI A68HM-E33 V2"
            };
            var videoCard = new VideoCard {
                Name = "Palit GeForce GT 710 Silent LP [NEAT7100HD46-2080H]"
            };
            var ram1 = new RAM {
                Name = "AMD Radeon R5 Entertainment Series [R532G1601U1S-U]"
            };
            var ram2 = new RAM {
                Name = "Patriot Signature [PSD32G16002]"
            };
            var soundCard = new SoundCard {
                Name = "ORIENT AU-01N"
            };

            db.Processors.Add(processor);
            db.MotherBoards.Add(motherBoard);
            db.VideoCards.Add(videoCard);
            db.RAMs.Add(ram1);
            db.RAMs.Add(ram2);
            db.SoundCards.Add(soundCard);
            await db.SaveChangesAsync();

            var workComputer = new Computer
            {
                Processor   = processor,
                MotherBoard = motherBoard,
                VideoCard   = videoCard,
                RAM1        = ram1,
                RAM2        = ram2,
                SoundCard   = soundCard
            };

            db.Computers.Add(workComputer);
            await db.SaveChangesAsync();

            var tom = new User
            {
                Name         = TomName,
                WorkComputer = workComputer
            };

            db.Users.Add(tom);

            await db.SaveChangesAsync();

            dbTransaction.Commit();
        }