public void Execute()
        {
            using (var context = new BikesContext())
            {
                foreach(var schedule in context.schedules.Where(d => d.start < DateTime.Now).Where(d => d.end > DateTime.Now).ToList())
                {
                    if(schedule.lastRun.DayOfYear == DateTime.Now.DayOfYear)
                        continue;
                    if (schedule.hour != DateTime.Now.Hour)
                        continue;
                    foreach(string bikeNumber in schedule.affectedBikes.Split(','))
                    {
                        int number;
                        if (!int.TryParse(bikeNumber, out number))
                            continue;
                        var bikes = context.Bike.Where(b => b.bikeNumber == number);
                        if (context.Bike.Where(b => b.bikeNumber == number).Count() != 1)
                            continue;
                        else
                            bikes.First().onInspectionHold = true;
                    }

                    schedule.lastRun = DateTime.Now;

                }
                context.SaveChanges();
            }
        }
 public static bool IsUserCashier(string userName)
 {
     using (var context = new BikesContext())
     {
         return context.BikeUser.Where(u => u.userName == userName).First().canCheckOutBikes;
     }
 }
 public static bool IsUserMechanic(string userName)
 {
     using (var context = new BikesContext())
     {
         return context.BikeUser.Where(u => u.userName == userName).First().canMaintainBikes;
     }
 }
Exemple #4
0
        public void Setup()
        {
            var builder = new DbContextOptionsBuilder <BikesContext>().UseSqlServer(ConnectionString);

            _context = new BikesContext(builder.Options);
            _service = new SalesPersonsService(_context);

            using (var transaction = _context.Database.BeginTransaction())
            {
                _context.SalesPersons.Add(new SalesPerson
                {
                    Id              = 1,
                    FirstName       = "Harecore",
                    LastName        = "Salesman",
                    Address         = "1 Street Ln",
                    Phone           = "321-321-4321",
                    TerminationDate = DateTime.MaxValue,
                    StartDate       = DateTime.MinValue,
                    Manager         = "Joe"
                });

                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [SalesPersons] ON");
                _context.SaveChanges();
                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [SalesPersons] OFF");
                transaction.Commit();
            }
        }
 public static bool IsUserAdmin(string userName)
 {
     using (var context = new BikesContext())
     {
         return context.BikeUser.Where(u => u.userName == userName).First().canAdministerSite;
     }
 }
        public void Execute()
        {
            using (var context = new BikesContext())
            {
                var set = context.settings.First();
                string appName = set.appName;
                int rentDays = set.maxRentDays;
                DateTime threshold = DateTime.Now.Subtract(new TimeSpan(rentDays, 0, 0, 0));
                List<CheckOut> checks = context.CheckOut.Where(i => !i.isResolved).Where(m => m.timeOut < threshold).ToList();

                var mail = new MailItem();
                foreach (var s in set.adminEmailList.Split(','))
                {
                    mail.To.Add(s);
                }
                mail.Subject = "Admin Bike Report - " + appName;
                mail.isHtml = true;
                mail.Body += "<div style=\"text-align: center; font-size: 24pt\">" + appName + " Admin Mailing</div>";
                mail.Body += "\n<div style=\"text-align: center; font-size: 20pt; color: gray;\">" + checks.Count().ToString() + " Overdue Bikes</div>";
                mail.Body += "<table><tr><th>Bike Number</th><th>Rental Date</th><th>User Name</th><th>Real Name</th><th>Phone Number</th></tr>";
                foreach (var check in checks)
                {
                    var user = context.BikeUser.Find(check.rider);
                    mail.Body += "<tr><td>" + context.Bike.Find(check.bike).bikeNumber.ToString() + "</td><td>" + check.timeOut.ToString() + "</td><td>" + user.userName + "</td><td>" + user.firstName + " " + user.lastName + "</td><td>" + user.phoneNumber + "</td></tr>";
                }
                mail.Body += "</table>";
                Mailing.queueMail(mail);
            }
        }
        async Task CreateCustomers(BikesContext context)
        {
            string[] names       = { "Andrew", "John", "Scott", "Ibon" };
            string[] lastnames   = { "Davis", "Smith", "Williams" };
            string[] creditCards = { "3767-8552-8051-1396", "3768-4662-3931-2047", "3427-6256-3187-6899", "3735-0437-5831-7278", "3483-9488-5688-8810" };

            foreach (var name in names)
            {
                foreach (var lastname in lastnames)
                {
                    var customer = new Customer()
                    {
                        FirstName        = name,
                        LastName         = lastname,
                        Address          = "15 Ski App Way, Redmond Heights Way",
                        City             = "Washington",
                        Country          = "USA",
                        Email            = $"{name}@outlook.com".ToLowerInvariant(),
                        LastOrder        = DateTime.UtcNow.AddDays(-1 * Randomize.Next(1, 40)),
                        Phone            = "555-555-555",
                        ZipCode          = "444-456",
                        State            = "Washington",
                        CreditCardNumber = creditCards[Randomize.Next(0, 4)],
                        RegistrationDate = DateTime.UtcNow.AddMonths(-1 * Randomize.Next(3, 6))
                    };

                    context.Customers.Add(customer);
                    await context.SaveChangesAsync();
                }
            }
        }
 public static bool IsUserMechanic(string userName)
 {
     using (var context = new BikesContext())
     {
         return(context.BikeUser.Where(u => u.userName == userName).First().canMaintainBikes);
     }
 }
 public static bool IsUserCashier(string userName)
 {
     using (var context = new BikesContext())
     {
         return(context.BikeUser.Where(u => u.userName == userName).First().canCheckOutBikes);
     }
 }
        public void Setup()
        {
            var builder = new DbContextOptionsBuilder <BikesContext>().UseSqlServer(ConnectionString);

            _context = new BikesContext(builder.Options);
            _service = new ProductsService(_context);

            using (var transaction = _context.Database.BeginTransaction())
            {
                _context.Products.Add(new Product
                {
                    Id                   = 1,
                    Manufacturer         = "Acme",
                    Name                 = "Toy",
                    SalePrice            = new decimal(1.25),
                    Style                = "Toddler",
                    PurchasePrice        = new decimal(1.50),
                    QuantityAvailable    = 5,
                    CommissionPercentage = new decimal(.05)
                });

                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Products] ON");
                _context.SaveChanges();
                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Products] OFF");
                transaction.Commit();
            }
        }
 public static bool IsUserAdmin(string userName)
 {
     using (var context = new BikesContext())
     {
         return(context.BikeUser.Where(u => u.userName == userName).First().canAdministerSite);
     }
 }
Exemple #12
0
        public void Setup()
        {
            var builder = new DbContextOptionsBuilder <BikesContext>().UseSqlServer(ConnectionString);

            _context = new BikesContext(builder.Options);
            _service = new CustomersService(_context);

            using (var transaction = _context.Database.BeginTransaction())
            {
                _context.Customers.Add(new Customer
                {
                    Id        = 1,
                    FirstName = "First",
                    LastName  = "Last",
                    Address   = "1 Street",
                    Phone     = "123-123-1234",
                    StartDate = DateTime.UtcNow
                });

                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Customers] ON");
                _context.SaveChanges();
                _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Customers] OFF");
                transaction.Commit();
            }
        }
        public void Setup()
        {
            var builder = new DbContextOptionsBuilder <BikesContext>().UseSqlServer(ConnectionString);

            _context    = new BikesContext(builder.Options);
            _controller = new CustomersController(_context);
        }
Exemple #14
0
        public void Execute()
        {
            if ((DateTime.Now.ToString("ddd") == "Fri" && DateTime.Now.Hour > 17) || DateTime.Now.ToString("ddd") == "Sat" || DateTime.Now.ToString("ddd") == "Sun" || (DateTime.Now.ToString("ddd") == "Mon" && DateTime.Now.Hour < 9))
            {
                return;
            }

            using (var context = new BikesContext())
            {
                var    set      = context.settings.First();
                string appName  = set.appName;
                int    rentDays = set.maxRentDays;
                foreach (var checkout in context.CheckOut.Where(i => !i.isResolved).ToList())
                {
                    if (checkout.timeOut.AddDays(rentDays) < DateTime.Now)
                    {
                        MailItem mail = new MailItem();
                        mail.To.Add(context.BikeUser.Find(checkout.rider).email);
                        mail.Subject = "Bike Now Overdue - " + appName;
                        mail.Body    = "Thank you for using the " + appName + ". You rented a bike on " + checkout.timeOut.ToShortDateString() + " at " + checkout.timeOut.ToShortTimeString() +
                                       ". Per our policy, your bike is now overdue, and failure to return it in a timely manner may result in charges to your account. Please return your bike as soon as possible.";
                        Mailing.queueMail(mail);
                    }
                }
            }
        }
        private async Task <BikesContext> CreateStoreDatabase(string connectionstring, int attempt = 1)
        {
            BikesContext context = null;

            try
            {
                var builder = new DbContextOptionsBuilder();
                builder.UseSqlServer(connectionstring);
                context = new BikesContext(builder.Options);
                var databaseCreated = await context.Database.EnsureCreatedAsync();

                if (!databaseCreated)
                {
                    context = null;
                }
            }
            catch (SqlException ex)
            {
                if (MustRetry(ex.Number, attempt))
                {
                    attempt++;
                    await CreateStoreDatabase(connectionstring, attempt);
                }
            }

            return(context);
        }
Exemple #16
0
        public void Execute()
        {
            using (var context = new BikesContext())
            {
                var             set       = context.settings.First();
                string          appName   = set.appName;
                int             rentDays  = set.maxRentDays;
                DateTime        threshold = DateTime.Now.Subtract(new TimeSpan(rentDays, 0, 0, 0));
                List <CheckOut> checks    = context.CheckOut.Where(i => !i.isResolved).Where(m => m.timeOut < threshold).ToList();

                var mail = new MailItem();
                foreach (var s in set.adminEmailList.Split(','))
                {
                    mail.To.Add(s);
                }
                mail.Subject = "Admin Bike Report - " + appName;
                mail.isHtml  = true;
                mail.Body   += "<div style=\"text-align: center; font-size: 24pt\">" + appName + " Admin Mailing</div>";
                mail.Body   += "\n<div style=\"text-align: center; font-size: 20pt; color: gray;\">" + checks.Count().ToString() + " Overdue Bikes</div>";
                mail.Body   += "<table><tr><th>Bike Number</th><th>Rental Date</th><th>User Name</th><th>Real Name</th><th>Phone Number</th></tr>";
                foreach (var check in checks)
                {
                    var user = context.BikeUser.Find(check.rider);
                    mail.Body += "<tr><td>" + context.Bike.Find(check.bike).bikeNumber.ToString() + "</td><td>" + check.timeOut.ToString() + "</td><td>" + user.userName + "</td><td>" + user.firstName + " " + user.lastName + "</td><td>" + user.phoneNumber + "</td></tr>";
                }
                mail.Body += "</table>";
                Mailing.queueMail(mail);
            }
        }
 async Task InitializeDatabaseData(BikesContext context)
 {
     Console.WriteLine("Initialize data");
     try
     {
         await CreateCustomers(context);
         await CreateStores(context);
         await CreateProducts(context);
         await CreateOrders(context);
     }
     catch (Exception ex)
     {
         // it´s sample data so log the error message and continue.
         Console.WriteLine(ex.Message);
     }
 }
        async Task CreateProducts(BikesContext context)
        {
            string[] names = { "HL Mountain Frame, Black", "Mountain-100 Black", "Mountain-100 Silver", "Road-250 Black",
                               "Touring-1000 Blue",        "Touring-2000 Blue",  "Touring-3000 Yellow" };

            string[] description =
            {
                "Cross-train, race, or just socialize on a sleek, aerodynamic bike designed for a woman. Advanced seat technology provides comfort all day.",
                "Our best value utilizing the same, ground-breaking frame technology as the ML aluminum frame."
            };

            var storeIds = context.Stores.Select(s => s.StoreId).ToList();

            foreach (var file in Directory.GetFiles($"sampledata/pictures/bikes", "*.png"))
            {
                byte[] picture = File.ReadAllBytes(file);
                foreach (var storeId in storeIds)
                {
                    try
                    {
                        var product = new Product()
                        {
                            Name           = names[Randomize.Next(0, names.Length - 1)],
                            OriginalPrice  = Randomize.Next(200, 800),
                            Discount       = Randomize.Next(10, 50),
                            RemainingUnits = Randomize.Next(10, 250),
                            Comments       = string.Empty,
                            Description    = description[Randomize.Next(0, description.Length - 1)],
                            Rating         = Randomize.Next(0, 5),
                            StoreId        = storeId,
                            Picture        = picture
                        };

                        context.Products.Add(product);
                        await context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        // it´s sample data so log the error message and continue.
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Exemple #19
0
 public void Execute()
 {
     using (var context = new BikesContext())
     {
         string appName = context.settings.First().appName;
         foreach (var charge in context.Charge.Where(i => !i.isResolved))
         {
             var mail = new MailItem();
             mail.To.Add(charge.user.email);
             mail.Subject = "Account Balance Reminder - " + appName;
             mail.Body    = "Thank you for using the " + appName + ". There is currently a pending charge on your account. Title: " + charge.title + " Description: " + charge.description +
                            ". The amount of the charge is $" + charge.amountCharged + ". Please review your account on our website for more details.";
             mail.isHtml = false;
             Mailing.queueMail(mail);
             charge.notificationsCounter += 1;
         }
         context.SaveChanges();
     }
 }
 public void Execute()
 {
     using (var context = new BikesContext())
     {
         string appName = context.settings.First().appName;
         foreach (var charge in context.Charge.Where(i => !i.isResolved))
         {
             var mail = new MailItem();
             mail.To.Add(charge.user.email);
             mail.Subject = "Account Balance Reminder - " + appName;
             mail.Body = "Thank you for using the " + appName + ". There is currently a pending charge on your account. Title: " + charge.title + " Description: " + charge.description +
                 ". The amount of the charge is $" + charge.amountCharged + ". Please review your account on our website for more details.";
             mail.isHtml = false;
             Mailing.queueMail(mail);
             charge.notificationsCounter += 1;
         }
         context.SaveChanges();
     }
 }
        async Task CreateStores(BikesContext context)
        {
            foreach (var storeName in stores)
            {
                var store = new Store()
                {
                    Name      = storeName,
                    Rating    = Randomize.Next(0, 5),
                    Address   = "15 Ski App Way, Redmond Heights Way",
                    City      = "Washington",
                    Country   = "USA",
                    Email     = "*****@*****.**",
                    Latitude  = 40.721847,
                    Longitude = -74.007326,
                    Phone     = "11",
                    State     = "Washington"
                };

                context.Stores.Add(store);
                await context.SaveChangesAsync();
            }
        }
        async Task CreateOrders(BikesContext context)
        {
            var customers = context.Customers.ToList();
            var stores    = context.Stores.Select(s => s.StoreId).ToList();

            foreach (var storeId in stores)
            {
                var products = context.Products.Select(p => p.ProductId).ToArray();
                foreach (var customer in customers)
                {
                    var numberOfUnits = Randomize.Next(1, 2);
                    var pricePerUnit  = Randomize.Next(50, 300);
                    var order         = new Order()
                    {
                        CustomerId = customer.CustomerId,
                        Date       = DateTime.UtcNow.AddDays(-1 * Randomize.Next(1, 40)),
                        Comments   = string.Empty,
                        Status     = Model.Enums.Status.Pending,
                        StoreId    = storeId,
                        TotalPrice = Randomize.Next(150, 700),
                        OrderLines = new List <OrderLine>()
                        {
                            new OrderLine()
                            {
                                NumberOfUnits = numberOfUnits,
                                TotalPrice    = pricePerUnit * numberOfUnits,
                                PricePerUnit  = pricePerUnit,
                                ProductId     = products[Randomize.Next(0, products.Count() - 1)]
                            }
                        }
                    };

                    context.Orders.Add(order);
                    await context.SaveChangesAsync();
                }
            }
            ;
        }
        public void Execute()
        {
            using (var context = new BikesContext())
            {
                foreach (var schedule in context.schedules.Where(d => d.start < DateTime.Now).Where(d => d.end > DateTime.Now).ToList())
                {
                    if (schedule.lastRun.DayOfYear == DateTime.Now.DayOfYear)
                    {
                        continue;
                    }
                    if (schedule.hour != DateTime.Now.Hour)
                    {
                        continue;
                    }
                    foreach (string bikeNumber in schedule.affectedBikes.Split(','))
                    {
                        int number;
                        if (!int.TryParse(bikeNumber, out number))
                        {
                            continue;
                        }
                        var bikes = context.Bike.Where(b => b.bikeNumber == number);
                        if (context.Bike.Where(b => b.bikeNumber == number).Count() != 1)
                        {
                            continue;
                        }
                        else
                        {
                            bikes.First().onInspectionHold = true;
                        }
                    }

                    schedule.lastRun = DateTime.Now;
                }
                context.SaveChanges();
            }
        }
        private async Task InitializeDefaultStoreDatabase(int attempt = 1)
        {
            try
            {
                Console.WriteLine("Initialize default store database");
                var builder = new DbContextOptionsBuilder();
                builder.UseSqlServer(_DefaultConnectionString);
                var context         = new BikesContext(builder.Options);
                var databaseCreated = await context.Database.EnsureCreatedAsync();

                if (databaseCreated)
                {
                    await InitializeDatabaseData(context);
                }
            }
            catch (SqlException ex)
            {
                if (MustRetry(ex.Number, attempt))
                {
                    attempt++;
                    await InitializeDefaultStoreDatabase(attempt);
                }
            }
        }
        public void Execute()
        {
            if ((DateTime.Now.ToString("ddd") == "Fri" && DateTime.Now.Hour > 17) || DateTime.Now.ToString("ddd") == "Sat" || DateTime.Now.ToString("ddd") == "Sun" || (DateTime.Now.ToString("ddd") == "Mon" && DateTime.Now.Hour < 9))
            {
                return;
            }

            using (var context = new BikesContext())
            {
                var set = context.settings.First();
                string appName = set.appName;
                int rentDays = set.maxRentDays;
                foreach (var checkout in context.CheckOut.Where(i => !i.isResolved).ToList())
                {
                    if (checkout.timeOut.AddDays(rentDays) < DateTime.Now)
                    {
                        MailItem mail = new MailItem();
                        mail.To.Add(context.BikeUser.Find(checkout.rider).email);
                        mail.Subject = "Bike Now Overdue - " + appName;
                        mail.Body = "Thank you for using the " + appName + ". You rented a bike on " + checkout.timeOut.ToShortDateString() + " at " + checkout.timeOut.ToShortTimeString() +
                            ". Per our policy, your bike is now overdue, and failure to return it in a timely manner may result in charges to your account. Please return your bike as soon as possible.";
                        Mailing.queueMail(mail);
                    }
                }
            }
        }
 public HomeController()
 {
     context = new BikesContext();
 }
 public CheckoutController()
 {
     context = new BikesContext();
 }
 public FeaturesController(UserManager <User> userManager, BikesContext context)
 {
     _UserManager = userManager;
     _Context     = context;
 }
Exemple #29
0
 public HomeController()
 {
     context = new BikesContext();
 }
 public ProductsService(BikesContext context)
 {
     _context = context;
 }
Exemple #31
0
 public CustomersController(BikesContext context)
 {
     _service = new CustomersService(context);
 }
 public MechanicController()
 {
     context = new BikesContext();
 }
 /// <summary>
 /// Initializes the controller with dependency injection.
 /// </summary>
 /// <param name="param">IExploreRepository implementation to use.</param>
 public ExploreController()
 {
     context = new BikesContext();
 }
 public SqlProductsRepository(BikesContext context)
 {
     _context = context;
 }
 public AccountController()
 {
     context = new BikesContext();
 }
 public AdminController()
 {
     context = new BikesContext();
 }
Exemple #37
0
 public MechanicController()
 {
     context = new BikesContext();
 }
Exemple #38
0
 public CheckoutController()
 {
     context = new BikesContext();
 }
 public AccountController()
 {
     context = new BikesContext();
 }
 public ReportsController(BikesContext context)
 {
     _service = new ReportsService(context);
 }
Exemple #41
0
 public SalesPersonsService(BikesContext context)
 {
     _context = context;
 }
Exemple #42
0
 public SqlStoresRepository(BikesContext context)
 {
     _context = context;
 }
Exemple #43
0
 public HazardsController(UserManager <User> userManager, BikesContext context)
 {
     _UserManager = userManager;
     _Context     = context;
 }