예제 #1
0
        static void Main(string[] args)
        {
            using (var dbContext = new NeoShopDbContextFactory().CreateDbContext(new string[] { }))
            {
                DbInitializer.Initialize(dbContext);
            }

            var alexGuid = Guid.NewGuid();

            using (var unitOfWork = UnitOfWorkFactory.Create())
            {
                var alexAccount = new PersonAccount()
                {
                    Id           = Guid.NewGuid(),
                    Login        = "******",
                    PasswordHash = "alex_PasswordHash",
                    PasswordSalt = "alex_Salt",
                };
                var alex = new Person()
                {
                    Id        = alexGuid,
                    FirstName = "Alex",
                    LastName  = "Popov",
                    BirthDate = DateTime.Parse("01.02.2001"),
                    Account   = alexAccount,
                };

                var maryAccount = new PersonAccount()
                {
                    Id           = Guid.NewGuid(),
                    Login        = "******",
                    PasswordHash = "mary_PasswordHash",
                    PasswordSalt = "mary_Salt",
                };
                var mary = new Person()
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "Mary",
                    LastName  = "Isaeva",
                    BirthDate = DateTime.Parse("02.03.2002"),
                    Account   = maryAccount,
                };

                unitOfWork.Persons.Insert(alex);
                unitOfWork.Persons.Insert(mary);

                unitOfWork.SaveChanges();
            }

            using (var unitOfWork = UnitOfWorkFactory.Create())
            {
                Console.WriteLine("Persons:");
                foreach (var person in unitOfWork.Persons.GetAll())
                {
                    Console.WriteLine($"\n{person.FirstName} {person.LastName} {person.BirthDate.ToShortDateString()}");
                    Console.WriteLine($"{person.Account.Login} {person.Account.PasswordHash} {person.Account.PasswordSalt}");
                }
                Console.WriteLine($"\nAccounts: {unitOfWork.PersonAccounts.GetAll().Count()}");
            }

            using (var unitOfWork = UnitOfWorkFactory.Create())
            {
                Console.WriteLine("\nDeleting alex...");
                unitOfWork.Persons.Delete(alexGuid);
                unitOfWork.SaveChanges();
                Console.WriteLine($"Accounts: {unitOfWork.PersonAccounts.GetAll().Count()}");
            }

            using (var unitOfWork = UnitOfWorkFactory.Create())
            {
                var customerBobAccount = new PersonAccount()
                {
                    Id           = Guid.NewGuid(),
                    Login        = "******",
                    PasswordHash = "bob_ph",
                    PasswordSalt = "bob_ps",
                };
                var customerBob = new Customer()
                {
                    AccountNumber = "111",
                    BirthDate     = DateTime.Today,
                    FirstName     = "Bob",
                    LastName      = "McBob",
                    Account       = customerBobAccount,
                };

                unitOfWork.Customers.Insert(customerBob);
                unitOfWork.SaveChanges();

                unitOfWork.Customers.Delete(customerBob);
                unitOfWork.SaveChanges();
            }

            Console.WriteLine("\nPress Enter to exit.");
            Console.ReadLine();
        }
예제 #2
0
        public static UnitOfWork Create()
        {
            var dbContext = new NeoShopDbContextFactory().CreateDbContext(new string[] { });

            return(Create(dbContext));
        }