예제 #1
0
 /// <summary>
 /// Creates a new lists of menu items for a user or logged admin.
 /// </summary>
 public VM_MainMenu()
 {
     if (ContextCredentials.CheckTheAdmin(App.User.Email, App.User.Password))
     {
         MenuItems = new ObservableCollection <MasterMenuItem>(new[]
         {
             new MasterMenuItem {
                 Id = 1, Title = "Your products", TargetType = typeof(Products_MainPage)
             },
             new MasterMenuItem {
                 Id = 2, Title = "Customers' orders", TargetType = typeof(Orders_MainPage)
             },
             new MasterMenuItem {
                 Id = 3, Title = "Season Sales", TargetType = typeof(View.Admin.Sales)
             },
         });
     }
     else
     {
         MenuItems = new ObservableCollection <MasterMenuItem>(new[]
         {
             new MasterMenuItem {
                 Id = 1, Title = "Products", TargetType = typeof(Products_MainPage)
             },
             new MasterMenuItem {
                 Id = 2, Title = "Shopping Cart", TargetType = typeof(Cart)
             },
             new MasterMenuItem {
                 Id = 3, Title = "Your orders", TargetType = typeof(View.Customer.Orders)
             }
         });
     }
 }
예제 #2
0
 /// <summary>
 /// Open a page for new product.
 /// </summary>
 public void GetNewProductPage()
 {
     if (ContextCredentials.CheckTheAdmin(App.User.Email, App.User.Password))
     {
         ((MainPage)Application.Current.MainPage).Detail = new ProductForm();
     }
 }
예제 #3
0
 public void DeleteSelectedItem(ProductItem item)
 {
     if (ContextCredentials.CheckTheAdmin(App.User.Email, App.User.Password))
     {
         if (Product.DeleteProduct(item.ID))
         {
             Application.Current.MainPage.DisplayAlert
             (
                 "Succesful operation",
                 "Product was marked as deleted",
                 "OK"
             );
             ((MainPage)Application.Current.MainPage).Detail = new Products_MainPage();
         }
         else
         {
             Application.Current.MainPage.DisplayAlert
             (
                 "Something went wrong",
                 "We were unable to delete the product",
                 "OK"
             );
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Main page for showing all products for admin and customer.
        ///
        /// Creates subpages containing all categories and products.
        /// </summary>
        public Products_MainPage()
        {
            /// Creates a new view-model.
            viewModel      = new VM_ProductMainPage();
            BindingContext = viewModel;
            if (ContextCredentials.CheckTheAdmin(App.User.Email, App.User.Password))
            {
                Title = "Your products";
                ToolbarItems.Add(new Xamarin.Forms.ToolbarItem("Add", "", viewModel.GetNewProductPage));
            }

            InitializeComponent();

            /// Creates tabs for all inherited pages.
            viewModel.GetPages(Children);
        }
예제 #5
0
 /// <summary>
 /// Gets content pages for a main product page.
 /// </summary>
 /// <param name="children">List of children pages of a main product page.</param>
 public void GetPages(IList <Page> children)
 {
     if (ContextCredentials.CheckTheAdmin(App.User.Email, App.User.Password))
     {
         children.Add(new View.Admin.Products("All"));
         foreach (Category category in Categories)
         {
             children.Add(new View.Admin.Products(category.Name));
         }
     }
     else
     {
         children.Add(new View.Customer.Products("All"));
         foreach (Category category in Categories)
         {
             children.Add(new View.Customer.Products(category.Name));
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Tries to get user with the input credentials from the database
        /// </summary>
        private void LogUserIn()
        {
            if (ContextCredentials.CheckTheAdmin(Email, Password))
            {
                App.User = new Customer(Email, Password);
                Application.Current.MainPage = new MainPage();
                return;
            }
            App.User = Customer.GetCustomer(Email, Password, App.User.GetCart());

            /// Unsuccesful operation
            if (App.User == null)
            {
                Application.Current.MainPage.DisplayAlert
                (
                    "Unsuccesfull login",
                    "Invalid login information",
                    "OK"
                );
                return;
            }
            Application.Current.MainPage = new MainPage();
        }