Esempio n. 1
0
        static void Main(string[] args)
        {
            GringottsDbContext gringottsDbContext  = new GringottsDbContext();
            UsersContext       usersDbContext      = new UsersContext();
            HospitalDbContext  hospitalDbDbContext = new HospitalDbContext();

//            InsertWizzards(gringottsDbContext);
//            InsertUsers(usersDbContext);
//            CreateHospitalDb(hospitalDbDbContext);
//            ModifyHospitalDb(hospitalDbDbContext);
//            GetUsersByEmailProvider(usersDbContext);
            RemoveInactiveUsers(usersDbContext);
        }
Esempio n. 2
0
        //Exercise 7
        static void InsertWizzards(GringottsDbContext db)
        {
            //some hardcoded data (no sql file given for this)
            var data = new List <WizardDeposit>()
            {
                new WizardDeposit
                {
                    FirstName             = "Albus",
                    LastName              = "Dumbledore",
                    Age                   = 150,
                    MagicWandCreator      = "Antioch Peverell",
                    MagicWandSize         = 15,
                    DepositStartDate      = new DateTime(2016, 10, 20),
                    DepositExpirationDate = new DateTime(2020, 10, 20),
                    DepositAmount         = 20000.24m,
                    DepositCharge         = 0.2m,
                    IsDepositExpired      = false
                },
                new WizardDeposit
                {
                    FirstName             = "Harry",
                    LastName              = "Poten",
                    Age                   = 16,
                    MagicWandCreator      = "Mincho Praznikov",
                    MagicWandSize         = 9,
                    DepositStartDate      = new DateTime(2014, 9, 15),
                    DepositExpirationDate = new DateTime(2018, 9, 15),
                    DepositAmount         = 15325.25m,
                    DepositCharge         = 0.5m,
                    IsDepositExpired      = false
                },
                new WizardDeposit
                {
                    FirstName             = "Emma",
                    LastName              = "Watson",
                    Age                   = 150,
                    MagicWandCreator      = "Hagrid Debeliya",
                    MagicWandSize         = 10,
                    DepositStartDate      = new DateTime(2014, 08, 25),
                    DepositExpirationDate = new DateTime(2018, 08, 25),
                    DepositAmount         = 7825.10m,
                    DepositCharge         = 0.5m,
                    IsDepositExpired      = false
                },
            };

            db.WizzardDeposits.AddRange(data);

            try
            {
                db.SaveChanges();
                Console.WriteLine("Entries successfully saved!");
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var dbEntityValidationResult in ex.EntityValidationErrors)
                {
                    foreach (var validationError in dbEntityValidationResult.ValidationErrors)
                    {
                        Console.WriteLine(validationError.ErrorMessage);
                    }
                }
            }
        }