Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var ctx = new GringottsContext();

            #region 19.	Deposits Sum for Ollivander Family
            //ctx.WizzardDeposits.Where(w => w.MagicWandCreator == "Ollivander family")
            //    .GroupBy(w => w.DepositGroup)
            //    .ToList()
            //    .ForEach(d =>
            //    {
            //        Console.WriteLine($"{d.Key} - {d.Sum(w => w.DepositAmount)}");
            //    });
            #endregion

            #region 20.	Deposits Filter
            //ctx.WizzardDeposits.Where(w => w.MagicWandCreator == "Ollivander family")
            //    .GroupBy(w => w.DepositGroup)
            //    .Where(d => d.Sum(w => w.DepositAmount.Value) < 150000)
            //    .OrderByDescending(d => d.Sum(w => w.DepositAmount))
            //    .ToList()
            //    .ForEach(d =>
            //    {
            //        Console.WriteLine($"{d.Key} - {d.Sum(w => w.DepositAmount)}");
            //    });
            #endregion
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            GringottsContext ctx = new GringottsContext();

            ctx.Database.Delete();
            ctx.Database.Create();

            var wizzard = new WizzardDeposits()
            {
                FirstName     = "Bate",
                LastName      = "Pesho",
                MagicWandSize = int.MaxValue - 10000,
                Age           = 20
            };

            var tran = ctx.Database.BeginTransaction();

            try
            {
                ctx.WizzardDeposits.Add(wizzard);
                ctx.SaveChanges();
                tran.Commit();
                System.Console.WriteLine("Bate Pesho added.");
            }
            catch (System.Exception)
            {
                tran.Rollback();
                System.Console.WriteLine("Neshto grumna.");
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            using (var ctx = new GringottsContext())
            {
                //19. DepositsSumForOlivanderFamily(ctx);

                DepositsFilter(ctx);
            }
        }
Exemplo n.º 4
0
        private static void DepositsSumForOlivanderFamily(GringottsContext ctx)
        {
            var depositGroups = ctx.WizzardDeposits.Where(c => c.MagicWandCreator == "Ollivander family").GroupBy(c => c.DepositGroup).Select(c => new { DepositGroup = c.Key, Sum = c.Sum(b => b.DepositAmount) }).ToList();

            foreach (var depositGroup in depositGroups)
            {
                Console.WriteLine($"{depositGroup.DepositGroup} - ${depositGroup.Sum}");
            }
        }
Exemplo n.º 5
0
        private static void DepositsFilter(GringottsContext ctx)
        {
            var deposits = ctx.WizzardDeposits.Where(c => c.MagicWandCreator == "Ollivander family").GroupBy(c => c.DepositGroup).Select(c => new { DepositGroup = c.Key, Sum = c.Sum(b => b.DepositAmount) }).OrderByDescending(c => c.Sum).Where(c => c.Sum < 150000).ToList();

            foreach (var deposit in deposits)
            {
                Console.WriteLine($"{deposit.DepositGroup} - ${deposit.Sum}");
            }
        }
Exemplo n.º 6
0
        public static void DepositSumForOllivanderFamily()
        {
            GringottsContext context = new GringottsContext();

            foreach (var group in context.WizzardDeposits.Select(x => x.DepositGroup).Distinct())
            {
                Console.WriteLine($"{group} {context.WizzardDeposits.Where(x => x.DepositGroup == group).Where(w => w.MagicWandCreator == "Ollivander family").Sum(x => x.DepositAmount)}");
            }
        }
Exemplo n.º 7
0
        private static void DepositSumForOlivanderFamily()
        {
            GringottsContext context = new GringottsContext();

            foreach (var group in context.WizzardDeposits.Where(d => d.MagicWandCreator == "Ollivander family").GroupBy(s => s.DepositGroup))
            {
                Console.WriteLine($"{group.Key} - {group.Sum(z => z.DepositAmount)}");
            }
        }
Exemplo n.º 8
0
        static void Main()
        {
            GringottsContext context = new GringottsContext();

            //Exercise 19
            //DepositSumForOllivanderFamily(context);

            //Exercise 20
            //DepositFilter(context);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var context = new GringottsContext();

            //19.Deposit Sum for Ollivander family
            //DepositsSumByOliverFamily(context);

            //20.Deposit Filter
            //DepositFilter(context);
        }
Exemplo n.º 10
0
        private static void DepositsSumByOliverFamily(GringottsContext context)
        {
            var groups = context.WizzardDeposits.Select(x => x.DepositGroup).Distinct();

            foreach (var g in groups)
            {
                Console.WriteLine($@"{g} - {context.WizzardDeposits
                    .Where(d => d.DepositGroup == g)
                    .Where(x => x.MagicWandCreator == "Ollivander family")
                    .Sum(s => s.DepositAmount)}");
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var ctx = new GringottsContext();

            ctx.Database.Initialize(true);

            Models.WizardDeposits dumbledore =
                new Models.WizardDeposits()
            {
                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,
            };

            ctx.Deposits.Add(dumbledore);

            try
            {
                ctx.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityvalidationError in
                         ex.EntityValidationErrors)
                {
                    foreach (var validatioError in
                             entityvalidationError
                             .ValidationErrors)
                    {
                        System.Diagnostics.Debug.Write("Property: " +
                                                       validatioError.PropertyName +
                                                       "Error: " + validatioError
                                                       .ErrorMessage);
                    }
                }
            }


            Console.WriteLine("Added WizardDeposits:");
            ctx.Deposits.Select(d => d.LastName).ToList()
            .ForEach(Console.WriteLine);
        }
Exemplo n.º 12
0
        private static void DepositSumForOllivanderFamily(GringottsContext context)
        {
            var wizzard = context.WizzardDeposits
                          .Where(w => w.MagicWandCreator == "Ollivander family")
                          .GroupBy(w => w.DepositGroup)
                          .Select(c => new
            {
                DepositGroup = c.Key,
                TotalSum     = c.Sum(s => s.DepositAmount)
            });


            foreach (var w in wizzard)
            {
                Console.WriteLine($"{w.DepositGroup} - {w.TotalSum} ");
            }
        }
Exemplo n.º 13
0
        private static void DepositFilter(GringottsContext context)
        {
            var filtered = new Dictionary <string, decimal?>();
            var groups   = context.WizzardDeposits.Select(x => x.DepositGroup).Distinct();

            foreach (var g in groups)
            {
                filtered[g] = context.WizzardDeposits
                              .Where(x => x.DepositGroup == g)
                              .Where(x => x.MagicWandCreator == "Ollivander family")
                              .Sum(s => s.DepositAmount);
            }
            foreach (var f in filtered.Where(x => x.Value < 150000m).OrderByDescending(g => g.Value))
            {
                Console.WriteLine($"{f.Key} - {f.Value}");
            }
        }
Exemplo n.º 14
0
        public static void DepositFilter()
        {
            GringottsContext context = new GringottsContext();

            const decimal lowestAmount = 150000m;
            Dictionary <string, decimal?> filteredDepositGroups = new Dictionary <string, decimal?>();

            foreach (var group in context.WizzardDeposits.Select(x => x.DepositGroup).Distinct())
            {
                filteredDepositGroups[group] = context.WizzardDeposits.Where(x => x.DepositGroup == group).Where(w => w.MagicWandCreator == "Ollivander family").Sum(x => x.DepositAmount);
            }

            foreach (var filteredDepositGroup in filteredDepositGroups.Where(g => g.Value < lowestAmount).OrderByDescending(g => g.Value))
            {
                Console.WriteLine($"{filteredDepositGroup.Key} - {filteredDepositGroup.Value}");
            }
        }
Exemplo n.º 15
0
        private static void DepositFilter()
        {
            GringottsContext             context = new GringottsContext();
            Dictionary <string, decimal> output  = new Dictionary <string, decimal>();

            foreach (var group in context.WizzardDeposits.Where(d => d.MagicWandCreator == "Ollivander family").GroupBy(s => s.DepositGroup))
            {
                if (group.Sum(x => x.DepositAmount) < 150000)
                {
                    output[group.Key] = (decimal)group.Sum(x => x.DepositAmount);
                }
            }

            foreach (var item in output.OrderByDescending(x => x.Value))
            {
                Console.WriteLine($"{item.Key} - {item.Value}");
            }
        }
        private static void Main(string[] args)
        {
            //The migrations were not needed for this exercises. I just tried different things with them;

            var context = new GringottsContext();

            WizzardDeposit dumbledoreDeposit = new WizzardDeposit()
            {
                FirstName             = "Albus",
                LastName              = "Dubledore",
                Age                   = 15,
                MagicWandCreator      = "Antioch Peverell",
                MagicWandSize         = 15,
                DepositStartDate      = new DateTime(2017, 03, 01),
                DepositExpirationDate = new DateTime(2020, 03, 01),
                DepositAmount         = 20000.24m,
                DepositCharge         = 0.2,
                IsDepositExpired      = false
            };

            context.WizzardDeposits.Add(dumbledoreDeposit);

            try
            {
                context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var ev in ex.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      ev.Entry.Entity.GetType().Name, ev.Entry.State);
                    foreach (var ve in ev.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }