private void profileButtonClick(object sender, RoutedEventArgs e) { using (var _context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { ProfileService _profileService = new ProfileService(_context); if (_profileService.GetCustomer((Application.Current as App).currentUser) != null) { Customer currentCustomer = _profileService.GetCustomer((Application.Current as App).currentUser); CustomerProfileWindow customerProfileWindow = new CustomerProfileWindow(); customerProfileWindow.userFirstName.Text = currentCustomer.FirstName; customerProfileWindow.userLastName.Text = currentCustomer.LastName; customerProfileWindow.userAddress.Text = currentCustomer.Address; customerProfileWindow.Show(); } else { Seller currentSeller = _profileService.GetSeller((Application.Current as App).currentUser); SellerProfileWindow sellerProfileWindow = new SellerProfileWindow(); sellerProfileWindow.userFirstName.Text = currentSeller.FirstName; sellerProfileWindow.userLastName.Text = currentSeller.LastName; sellerProfileWindow.userAddress.Text = currentSeller.Address; sellerProfileWindow.Show(); } } }
private void writeToSellerClicked(object sender, RoutedEventArgs e) { FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); ChatService chatService = new ChatService(context); ProfileService profileService = new ProfileService(context); Chat chat; if ((Application.Current as App).currentUser == null) { MessageBox.Show("Вы не авторизованы в системе"); return; } if (chatService.Get(SellerId, profileService.GetCustomer((Application.Current as App).currentUser).Id) == null) // Если чата нет { chat = new Chat { SellerId = SellerId, CustomerId = profileService.GetCustomer((Application.Current as App).currentUser).Id }; chatService.Create(chat.SellerId, chat.CustomerId); } else // если чат есть { chat = chatService.Get(SellerId, profileService.GetCustomer((Application.Current as App).currentUser).Id); } ChatWindow chatWindow = new ChatWindow(chat); chatWindow.ShowDialog(); }
private void ListBoxCategories() { using (var _context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { CategoryService categoryService = new CategoryService(_context); listBoxCategories.ItemsSource = categoryService.GetAll(); } }
private void searchBNClick(object sender, RoutedEventArgs e) { using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { Search search = new Search(); var products = search.FindOfProduct(searchTB.Text, 10, context); // добавить вывод как лист в xaml-е } }
public AddProductWindow() { InitializeComponent(); FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); CategoryService categoryService = new CategoryService(context); categoriesList.ItemsSource = categoryService.GetAll(); }
private void categoriesListSelected(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = (ComboBox)sender; Category selectedCategory = (Category)comboBox.SelectedItem; FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); ProductService productService = new ProductService(context); productsList.ItemsSource = productService.GetAllByCategory(selectedCategory); }
//нужно connection string добавить public CartWindows() { InitializeComponent(); using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { LBCarts.ItemsSource = context.Carts; } //Нужно доработать вывод продуктов }
private void LoadClick(object sender, RoutedEventArgs e) { using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { ProfileService profileService = new ProfileService(context); profileService.UpdateImage(imageUrl.Text, (Application.Current as App).currentUser); } MessageBox.Show("Фотография успешно загружена"); this.Close(); }
private void sendMessageBtnClicked(object sender, RoutedEventArgs e) { FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); ChatService chatService = new ChatService(context); Message message = new Message { Value = messageTB.Text }; chatService.AddMessage(currentChat, message); }
private void listBoxCategoriesCategoryClicked(object sender, MouseButtonEventArgs e) { var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem; if (item != null) { using (var _context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { var sellerProductService = new SellerProductService(_context); var sellerProducts = sellerProductService.ShowSellerProducts(item.Content.ToString()); listBoxProductSellers.ItemsSource = sellerProducts; } } }
private void saveChangesButtonClick(object sender, RoutedEventArgs e) { FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); ProfileService profileService = new ProfileService(context); Customer customer = new Customer { User = (Application.Current as App).currentUser, FirstName = userFirstName.Text, LastName = userLastName.Text, Address = userAddress.Text }; profileService.UpdateProfile(customer, (Application.Current as App).currentUser); MessageBox.Show("Данные успешно сохранены"); this.Close(); }
private void SignUpButtonClicked(object sender, RoutedEventArgs e) { if (customerRB.IsChecked == true) { Customer customer = new Customer { UserId = (Application.Current as App).currentUser.Id, FirstName = userFirstName.Text, LastName = userLastName.Text, Address = userAddress.Text }; using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { ProfileService profileService = new ProfileService(context); profileService.Add(customer); } } else if (sellerRB.IsChecked == true) { Seller seller = new Seller { UserId = (Application.Current as App).currentUser.Id, FirstName = userFirstName.Text, LastName = userLastName.Text, Address = userAddress.Text }; using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { ProfileService profileService = new ProfileService(context); profileService.Add(seller); } } else { MessageBox.Show("Выберите вашу роль"); return; } MessageBox.Show("Аккаунт успешно зарегестрирован."); this.Close(); mainWindow.profileButton.Visibility = Visibility.Visible; mainWindow.cartButton.Visibility = Visibility.Visible; mainWindow.signInButton.Visibility = Visibility.Collapsed; }
private void addProductClicked(object sender, RoutedEventArgs e) { FarmersMarketContext context = new FarmersMarketContext((Application.Current as App).ConnectionString); ProfileService profileService = new ProfileService(context); SellerProductService sellerProductService = new SellerProductService(context); if (sellerProductService.AddSellerProduct((Product)productsList.SelectedItem, profileService.GetSeller((Application.Current as App).currentUser), Int32.Parse(quantityTB.Text), Int32.Parse(priceTB.Text), descriptionTB.Text, nameTB.Text) != null) { MessageBox.Show("Товар успешно добавлен"); this.Close(); return; } else { MessageBox.Show("Необходимо заполнить все поля!"); return; } }
private void listBoxProductSellersProductClicked(object sender, MouseButtonEventArgs e) { var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem; if (item != null) { using (var _context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { var sellerProductService = new SellerProductService(_context); var sellerProduct = sellerProductService.GetSellerProduct(item.Content.ToString()); ProductWindow productWindow = new ProductWindow(Guid.Parse(item.Content.ToString())); productWindow.name.Text = sellerProduct.Name; productWindow.price.Text = sellerProduct.Price.ToString(); productWindow.quantity.Text = sellerProduct.Count.ToString(); productWindow.ShowDialog(); } } }
private void ButtonAddToCart(object sender, RoutedEventArgs e) { using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString)) { var cartService = new CartService(context); var sellerProduct = context.SellerProducts.SingleOrDefault(product => product.Id == SellerId); var customer = context.Customers.SingleOrDefault(user => user.UserId == (Application.Current as App).currentUser.Id); var cart = new Cart { SellerProduct = sellerProduct, Customer = customer, Count = sellerProduct.Count }; cartService.AddProductToCart(cart); } MessageBox.Show("Товар добавлен в корзину"); }
public List <Product> FindOfProduct(string productName, int count, FarmersMarketContext context) { int page = 0; var products = from item in context.Products where item.Name.Contains(productName) select item; int productCount = products.Count(); if (productCount == 0) { return(new List <Product>()); } page = productCount / count; if (productCount % count != 0) { page++; } return(ToPagination(products.ToList <Product>(), page, count)); }
public ProfileService(FarmersMarketContext context) { this.context = context; }
public AuthService(FarmersMarketContext context) { this.context = context; }
public ChatService(FarmersMarketContext context) { this.context = context; }
public SellerProductService(FarmersMarketContext context) { this.context = context; }
public CategoryService(FarmersMarketContext context) { this.context = context; }