コード例 #1
0
 //create Credit Card form
 //1 user can have several credit cards stored
 //GET: Account/PaymentCard
 public ActionResult Card()
 {
     using (var context = new OnlineStoreContext())
     {
         return(View());
     }
 }
コード例 #2
0
 public ActionResult UpdateAddress(BillingAddress address)
 {
     using (var context = new OnlineStoreContext())
     {
         return(RedirectToAction("Index"));
     }
 }
コード例 #3
0
        // GET: Product
        public ActionResult Index()
        {
            OnlineStoreContext   onlineStoreContext = new OnlineStoreContext();
            List <ProductDetail> products           = onlineStoreContext.Products.ToList();

            return(View(products));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: almiskov/it-nordic-cs
        private static void InsertProducts()
        {
            var bread = new Product()
            {
                Name = "Fan", Price = 1500
            };
            var liquid = new Product[]
            {
                new Product {
                    Name = "TV", Price = 30000
                },
                new Product {
                    Name = "Oven", Price = 10000
                }
            };

            using (var context = new OnlineStoreContext())
            {
                context.Products.Add(bread);

                context.AddRange(liquid);

                context.SaveChanges();
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: almiskov/it-nordic-cs
        private static void InsertCustomers()
        {
            var customer = new Customer()
            {
                Name = "Anna1"
            };
            var customerSet = new Customer[]
            {
                new Customer {
                    Name = "Ivan1"
                },
                new Customer {
                    Name = "Pavel1"
                }
            };

            using (var context = new OnlineStoreContext())
            {
                //context.Customers.Add(customer);
                context.Add(customer);
                context.AddRange(customerSet);

                context.SaveChanges();
            }
        }
コード例 #6
0
        public static void Initialize(OnlineStoreContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            //if (context.Users.Any())
            //{
            //    return;   // DB has been seeded
            //}

            var users = new User[]
            {
                new User {
                    Name = "Carson", Password = "******"
                },
                new User {
                    Name = "Meredith", Password = "******"
                },
                new User {
                    Name = "Arturo", Password = "******"
                },
            };

            context.Users.AddRange(users);
            context.SaveChanges();
        }
コード例 #7
0
        protected override void Seed(OnlineStoreContext context)
        {
            if (!context.Users.Any(x => x.Role == UserRole.Admin))
            {
                var adminUser = new User
                {
                    Username  = "******",
                    Password  = "******",
                    FirstName = "Pesho",
                    LastName  = "Bradata",
                    EMail     = "[email protected]",
                    Role      = UserRole.Admin,
                    Address   = new Address()
                    {
                        AddressText = "Server room 1", Town = new Town()
                        {
                            Name = "Plovdiv"
                        }
                    }
                };

                var firstSupplier = new Supplier
                {
                    Name    = "Awful Creatures Ltd.",
                    Phone   = "+35929110101",
                    Address = new Address()
                    {
                        AddressText = "Staria Lebed 1", Town = new Town()
                        {
                            Name = "Varna"
                        }
                    }
                };
                context.Users.Add(adminUser);
                context.Suppliers.Add(firstSupplier);
                context.SaveChanges();

                var demoClient = new User
                {
                    Username    = "******",
                    Password    = "******",
                    FirstName   = "Mara",
                    LastName    = "Hubavicata",
                    EMail       = "*****@*****.**",
                    Role        = UserRole.Client,
                    ReferalUser = context.Users.First(),
                    Address     = new Address()
                    {
                        AddressText = "Carigradsko shose 1", Town = new Town()
                        {
                            Name = "Tutrakan"
                        }
                    }
                };

                context.Users.Add(demoClient);
                context.SaveChanges();
            }
        }
コード例 #8
0
ファイル: DataSeeder.cs プロジェクト: vzuga/idp
 public static void SeedData(this IApplicationBuilder app)
 {
     using (var context = new OnlineStoreContext())
     {
         if (!context.Database.EnsureCreated())
         {
             context.Database.Migrate();
         }
     }
 }
コード例 #9
0
        public ActionResult Cards()
        {
            using (var context = new OnlineStoreContext())
            {
                var userId  = User.Identity.GetUserId();
                var cardsOp = context.PaymentOptions.Where(p => p.CustomerId == userId).ToList();

                return(View(cardsOp));
            }
        }
コード例 #10
0
        //purpose obtain orders that belong to 1 user; therefore create several orders/customer, therefore create ToList; several orderids are linked to one Customer
        //there is no order form as this is used to display items that have been ordered
        //purchaseddetails table-this contains details of items ordered/customer
        //user logins ensure to view their purchased details. userid is id given to user-user identifier. match the userId (loggin id ) to custoemrid
        //GET method as we are not modifiying anything
        public ActionResult Orders()
        {
            using (var context = new OnlineStoreContext())
            {
                var userId = User.Identity.GetUserId();
                var orders = context.PurchasedDetails.Where(p => p.CustomerId == userId).ToList();

                return(View(orders));
            }
        }
コード例 #11
0
        public Task Invoke(HttpContext context, IServiceProvider serviceProvider, OnlineStoreContext dbContext)
        {
            if (!(context.Session.Keys.Contains("starting")))
            {
                DbInitializer.Initialize(dbContext);
                context.Session.SetString("starting", "Yes");
            }

            // Call the next delegate/middleware in the pipeline
            return(_next.Invoke(context));
        }
コード例 #12
0
        public ViewModelListProduct()
        {
            Context = new OnlineStoreContext();

            ShowItems = new DelegateCommand(() => this.Show());

            ListFilter = new List <string>
            {
                "Products", "by Clients"
            };
        }
コード例 #13
0
 public static void SeedData(this IApplicationBuilder app)
 {
     using (var serviceScope = app.ApplicationServices
                               .GetRequiredService <IServiceScopeFactory>()
                               .CreateScope())
     {
         var context = serviceScope.ServiceProvider.GetService <OnlineStoreContext>();
         _context = context;
         context.Database.Migrate();
         MigrateStaticData();
     }
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: basalduk/it-nordic-cs
        private static void InsertCustomers()
        {
            var customer = new Customer {
                Name = "Nikolay"
            };

            using (var context = new OnlineStoreContext())
            {
                context.Customers.Add(customer);
                context.SaveChanges();
            }
        }
コード例 #15
0
        public ActionResult Addresses()
        {
            using (var context = new OnlineStoreContext())
            {
                var userId = User.Identity.GetUserId();

                //return a list of billing addresses where the customerid == userid
                var billingAddresses = context.BillingAddress.Where(p => p.CustomerId == userId).ToList();

                return(View(billingAddresses));
            }
        }
コード例 #16
0
        public ViewModelListClients()
        {
            Context = new OnlineStoreContext();

            Show = new DelegateCommand(() => this.ShowItems());

            //Начальная инициализация списка с фильтрами.
            ListFilter = new List <string>
            {
                "Clients", "by Managers", "by Status"
            };
        }
コード例 #17
0
        public UnitOfWork(OnlineStoreContext context)
        {
            _context = context;

            UserAddress = new UserAddressRepository(_context);
            Products    = new ProductRepository(_context);

            Orders     = new OrderRepository(_context);
            OrderItems = new OrderItemRepository(_context);

            ShoppingCarts     = new ShoppingCartRepository(_context);
            ShoppingCartItems = new ShoppingCartItemRepository(_context);
        }
コード例 #18
0
 public AuthController(OnlineStoreContext context,
                       SignInManager <User> signInMgr,
                       UserManager <User> userMgr,
                       IPasswordHasher <User> hasher,
                       ILogger <AuthController> logger,
                       IConfigurationRoot config)
 {
     _context   = context;
     _signInMgr = signInMgr;
     _logger    = logger;
     _userMgr   = userMgr;
     _hasher    = hasher;
     _config    = config;
 }
コード例 #19
0
ファイル: Program.cs プロジェクト: nakklevaar/it-nordic-cs
        private static void UpdateProductsDisconnected()
        {
            var product = new Product
            {
                Id    = 1,
                Name  = "Test1",
                Price = 10M - 10M * 0.1M
            };

            using (var newContext = new OnlineStoreContext())
            {
                newContext.Products.Update(product);
                newContext.SaveChanges();
            }
        }
コード例 #20
0
 private static void SelectCustomers()
 {
     using (var context = new OnlineStoreContext())
     {
         string name = "Mikhail";
         //var allCustomers = context.Customers
         //    .Where(c => c.Name == name)
         //    .ToList();
         var customers = context.Customers.ToList();
         foreach (var customer in customers)
         {
             Console.WriteLine($"Customer: {customer.Name} has id: {customer.Id}");
         }
     }
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: basalduk/it-nordic-cs
        private static void UpdateCustomersDisconnected()
        {
            var product = new Product
            {
                Id    = 1,
                Name  = "TEST",
                Price = 10m - 10m * 0.1m
            };

            using (var newContext = new OnlineStoreContext())
            {
                newContext.Products.Update(product);
                newContext.SaveChanges();
            }
        }
コード例 #22
0
 private static void SelectCustomers()
 {
     using (var context = new OnlineStoreContext())
     {
         string tom = "Tom";
         // var allCustomers = context
         //.Customers
         //.Where(x=>x.Name==tom)
         //.ToList();
         var customers = context.Customers.ToList();
         foreach (var customer in customers)
         {
             Console.WriteLine($"Customer{customer.Name} has ID = {customer.Id}");
         }
     }
 }
コード例 #23
0
ファイル: Program.cs プロジェクト: basalduk/it-nordic-cs
        private static void SelectCustomer()
        {
            using (var context = new OnlineStoreContext())
            {
                //string p = "Mikhail";
                //var allCustomers = context
                //    .Customers
                //    .Where(x=> x.Name==p)
                //    .ToList();

                var customers = context.Customers.ToList();
                foreach (var customer in customers)
                {
                    Console.WriteLine($"{customer.Id}, {customer.Name}");
                }
            }
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: nakklevaar/it-nordic-cs
        private static void SelectCustomers()
        {
            using (var context = new OnlineStoreContext())
            {
                //string alex = "alex 9";

                //var allCustomers1 = context.Customers.Where(c=>c.Name == "Alex 11").ToList();

                //var allCustomers2 = context.Customers.Where(c => c.Name == alex).ToList();

                var customers = context.Customers.ToList();
                foreach (var customer in customers)
                {
                    Console.WriteLine($"Customer '{customer.Name}' has ID = {customer.Id}");
                }
            }
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: almiskov/it-nordic-cs
        private static void UpdateProductsDisconnected()
        {
            //var product = _context.Products.First();
            //product.Price *= 1.1M;

            var product = new Product()
            {
                Id    = 1,
                Name  = "Bread",
                Price = 50M - 50M * 0.1M
            };

            using (var newContext = new OnlineStoreContext())
            {
                newContext.Products.Update(product);
                newContext.SaveChanges();
            }
        }
コード例 #26
0
ファイル: ViewModelClient.cs プロジェクト: YuriNewProgger/CRM
        public ViewModelClient()
        {
            Context = new OnlineStoreContext();

            ShowWindowForCreateNewClient = new DelegateCommand(() => this.ShowClientCreationWindow());
            CreateNewClient           = new DelegateCommand(() => this.CreateClient());
            CloseWinCreationNewClient = new DelegateCommand(() => this.CloseWindowCreationNewClient());

            ShowWindowForEditSelectedClient = new DelegateCommand(() => this.ShowWindowEditSelectedClient());
            EditSelectedClient         = new DelegateCommand(() => this.EditClient());
            CloseWinEditSelectedClient = new DelegateCommand(() => this.CloseWindowEditSelectedClient());

            DeleteClient = new DelegateCommand(() => this.DeleteSelectedClient());

            Clients  = Context.Clients.ToList();
            Managers = Context.Managers.ToList();
            Statuses = Context.Status.ToList();
        }
コード例 #27
0
        //check if the billing address is null. If null redirect to new address. If not null display address; AddressViewModel is found in the accountviewmodel
        public ActionResult Address(int?addressId = null)
        {
            var model = new AddressViewModel()
            {
                BillingAddress = new BillingAddress(),
                CountriesList  = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                                 .Select(p =>
                {
                    try
                    {
                        return(new SelectListItem()
                        {
                            Text = new RegionInfo(p.LCID).DisplayName,
                            Value = p.LCID.ToString()
                        });
                    }
                    catch
                    {
                        return(null);
                    }
                })
                                 .Where(p => p != null)
                                 .DistinctBy(p => p.Text)
                                 .OrderBy(p => p.Text)
                                 .ToList()
            };

            if (addressId == null)
            {
                return(View(model));
            }

            using (var context = new OnlineStoreContext())
            {
                var userId  = User.Identity.GetUserId();
                var address = context.BillingAddress.Where(p => p.CustomerId == userId).Single();

                model.BillingAddress = address;

                return(View(model));
            }
        }
コード例 #28
0
        public ViewModelProduct()
        {
            Context = new OnlineStoreContext();

            ShowWinCreateProduct  = new DelegateCommand(() => this.ShowWindowCreateNewProduct());
            CreateNewProduct      = new DelegateCommand(() => this.CreateProduct());
            CloseWinCreateProduct = new DelegateCommand(() => this.CloseWindowCreateProduct());

            ShowWinEditProduct       = new DelegateCommand(() => this.ShowWinEditSelectedProduct());
            SaveChangesEditProduct   = new DelegateCommand(() => this.EditProduct());
            CancelChangesEditProduct = new DelegateCommand(() => this.CloseWindowEditSelectedProduct());

            DeleteProduct = new DelegateCommand(() => this.DeleteSelectedProduct());

            Products = Context.Products.ToList();

            SubscriptionTypes = Context.SubscriptionTypes.ToList();

            SubscriptionTerms = Context.SubscriptionTerms.ToList();
        }
コード例 #29
0
        private static void InsertCustomers()
        {
            var customer = new Customer {
                Name = "Mikhail2"
            };

            //_context.Add(customer);
            //var customerSet = new Customer[]
            //{
            //    new Customer { Name = "Nikolay" },
            //    new Customer {Name = "Vladislav"}
            //};

            using (var context = new OnlineStoreContext())
            {
                //context.Customers.Add(customer);
                context.Add(customer);
                //context.AddRange(customerSet);
                //context.SaveChanges();
            }
        }
コード例 #30
0
        private static void InsertProduct()
        {
            var product = new Product {
                Name = "Bread", Price = 10
            };
            var productSet = new Product[]
            {
                new Product {
                    Name = "Milk", Price = 62
                },
                new Product {
                    Name = "Cheese", Price = 39
                }
            };

            using (var context = new OnlineStoreContext())
            {
                context.Products.Add(product);
                context.Products.AddRange(productSet);
                context.SaveChanges();
            }
        }