private void Add_Product_Loaded(object sender, RoutedEventArgs e)
        {
            context    = DataContextAccesor.GetDataContext();
            categories = context.Categories.Where(x => x.SubCategoryId == null).Include(x => x.SubCategories).ToList();
            CategoryCombo.ItemsSource = categories;

            //CategoryCombo.SelectedIndex = 0;
            MainGrid.DataContext = newProduct;
            PhotoName.Content    = "";
        }
示例#2
0
        private void OrdersLoaded(object sender, RoutedEventArgs e)
        {
            DataContext context = DataContextAccesor.GetDataContext();

            var user = LoginService.user;

            orderlist = context.Order.Include(x => x.Ordered).ThenInclude(x => x.Product).Where(x => x.UserDataId == user.UserDataId).ToList();

            OrderList.ItemsSource = orderlist;
        }
示例#3
0
        public Cart()
        {
            InitializeComponent();
            var context  = DataContextAccesor.GetDataContext();
            var products = context.Products.ToList();
            var list     = CartHelper.getCart();

            if (list == null)
            {
                Items = new ObservableCollection <OrderItem>();
            }
            else
            {
                Items = new ObservableCollection <OrderItem>(list);
            }

            CartGrid.ItemsSource = Items;
        }
        private void Edit_User_Data_Click(object sender, RoutedEventArgs e)
        {
            var context = DataContextAccesor.GetDataContext();

            try
            {
                context.Update(user);
                context.SaveChanges();

                MessageBox.Show("Zmieniono dane", "Zmiana Danych", MessageBoxButton.OK, MessageBoxImage.Information);

                this.NavigationService.Navigate(new SalesProducts());
            }
            catch (DbUpdateConcurrencyException)
            {
                MessageBox.Show("Błąd zmiany danych", "Zmiana Danych", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
0
 static AccountManager()
 {
     context = DataContextAccesor.GetDataContext();
 }
示例#6
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);


            var context = DataContextAccesor.GetDataContext();

            context.Database.EnsureCreated();

            if (await context.Categories.AnyAsync() == false) // drop bazy
            {
                List <Category> categoryList = new List <Category>()
                {
                    new Category {
                        Name = "AGD", SubCategoryId = null
                    },
                    new Category {
                        Name = "TV", SubCategoryId = null
                    },
                    new Category {
                        Name = "Telefony", SubCategoryId = null
                    },
                    new Category {
                        Name = "Komputery", SubCategoryId = null
                    },
                    new Category {
                        Name = "Konsole", SubCategoryId = null
                    },
                    new Category {
                        Name = "Gadżety", SubCategoryId = null
                    },
                };



                string directory = Path.Combine(Directory.GetCurrentDirectory(), "Image");
                var    path      = Directory.GetFiles(directory);

                await context.Categories.AddRangeAsync(categoryList);


                await context.SaveChangesAsync();

                List <Category> subCategoryList = new List <Category>()
                {
                    new Category {
                        Name = "Pralki", SubCategoryId = categoryList[0].Id
                    },
                    new Category {
                        Name = "Zmywarki", SubCategoryId = categoryList[0].Id
                    },
                    new Category {
                        Name = "Lodowki", SubCategoryId = categoryList[0].Id
                    },
                    new Category {
                        Name = "Ekspresy", SubCategoryId = categoryList[0].Id
                    },
                    new Category {
                        Name = "Kino domowe", SubCategoryId = categoryList[1].Id
                    },
                    new Category {
                        Name = "Telewizory", SubCategoryId = categoryList[1].Id
                    },
                    new Category {
                        Name = "DVD", SubCategoryId = categoryList[1].Id
                    },
                    new Category {
                        Name = "Akcesoria RTV", SubCategoryId = categoryList[1].Id
                    },
                    new Category {
                        Name = "Smartfony", SubCategoryId = categoryList[2].Id
                    },
                    new Category {
                        Name = "Tablety", SubCategoryId = categoryList[2].Id
                    },
                    new Category {
                        Name = "Telefony Stacjonarne", SubCategoryId = categoryList[2].Id
                    },
                    new Category {
                        Name = "PC", SubCategoryId = categoryList[3].Id
                    },
                    new Category {
                        Name = "Laptopy", SubCategoryId = categoryList[3].Id
                    },
                    new Category {
                        Name = "Notebooki", SubCategoryId = categoryList[3].Id
                    },
                    new Category {
                        Name = "Drukarki", SubCategoryId = categoryList[3].Id
                    },
                    new Category {
                        Name = "Urządzenia peryferyjne", SubCategoryId = categoryList[3].Id
                    },
                    new Category {
                        Name = "X-Box", SubCategoryId = categoryList[4].Id
                    },
                    new Category {
                        Name = "Playstation", SubCategoryId = categoryList[4].Id
                    },
                    new Category {
                        Name = "Nintendo", SubCategoryId = categoryList[4].Id
                    },
                    new Category {
                        Name = "Smartwatche", SubCategoryId = categoryList[5].Id
                    },
                    new Category {
                        Name = "Czytniki E-bookow", SubCategoryId = categoryList[5].Id
                    },
                    new Category {
                        Name = "Nawigacje GPS", SubCategoryId = categoryList[5].Id
                    },
                };

                await context.Categories.AddRangeAsync(subCategoryList);


                await context.SaveChangesAsync();

                List <Product> productList = new List <Product>();
                string         json        = "";
                using (StreamReader str = new StreamReader("generated.json"))
                {
                    json = str.ReadToEnd();
                }
                productList = JsonSerializer.Deserialize <List <Product> >(json);
                Random       rand    = new Random(); //losowanie obrazka
                ImageResizer resizer = new ImageResizer();
                foreach (var product in productList)
                {
                    var item = path[rand.Next(0, path.Length)];


                    product.Photo      = resizer.resize(item);
                    product.CategoryId = subCategoryList[product.CategoryId.Value - 1].Id;
                }

                await context.Products.AddRangeAsync(productList);

                await context.SaveChangesAsync();

                if (await context.Users.AnyAsync() == false)
                {
                    User admin = new User
                    {
                        Name     = "admin",
                        Password = "******",
                        Role     = AppRole.Admin
                    };

                    AccountManager.RegisterAdmin(admin);

                    //User user = new User
                    //{
                    //    Name = "user",
                    //    Password = "******",
                    //    Role = AppRole.User
                    //};

                    //AccountManager.Register(user);
                }
            }


            MainWindow w = new MainWindow();

            w.Show();
        }
 public CartDelivery()
 {
     InitializeComponent();
     context = DataContextAccesor.GetDataContext();
 }