Example #1
0
        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();
                }
            }
        }
Example #2
0
        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();
        }
Example #3
0
 private void ListBoxCategories()
 {
     using (var _context = new FarmersMarketContext((Application.Current as App).ConnectionString))
     {
         CategoryService categoryService = new CategoryService(_context);
         listBoxCategories.ItemsSource = categoryService.GetAll();
     }
 }
Example #4
0
 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-е
     }
 }
Example #5
0
        public AddProductWindow()
        {
            InitializeComponent();

            FarmersMarketContext context         = new FarmersMarketContext((Application.Current as App).ConnectionString);
            CategoryService      categoryService = new CategoryService(context);

            categoriesList.ItemsSource = categoryService.GetAll();
        }
Example #6
0
        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);
        }
Example #7
0
        //нужно connection string добавить
        public CartWindows()
        {
            InitializeComponent();

            using (var context = new FarmersMarketContext((Application.Current as App).ConnectionString))
            {
                LBCarts.ItemsSource = context.Carts;
            }
            //Нужно доработать вывод продуктов
        }
Example #8
0
 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();
 }
Example #9
0
        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);
        }
Example #10
0
        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;
                }
            }
        }
Example #11
0
        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();
        }
Example #12
0
        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;
        }
Example #13
0
        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;
            }
        }
Example #14
0
        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();
                }
            }
        }
Example #15
0
        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("Товар добавлен в корзину");
        }
Example #16
0
        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));
        }
Example #17
0
 public ProfileService(FarmersMarketContext context)
 {
     this.context = context;
 }
Example #18
0
 public AuthService(FarmersMarketContext context)
 {
     this.context = context;
 }
Example #19
0
 public ChatService(FarmersMarketContext context)
 {
     this.context = context;
 }
Example #20
0
 public SellerProductService(FarmersMarketContext context)
 {
     this.context = context;
 }
Example #21
0
 public CategoryService(FarmersMarketContext context)
 {
     this.context = context;
 }