Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Debug.WriteLine(loaded);
            if (!IsPostBack)
            {
                String productId = null;
                loaded = true;
                if (!String.Equals(Request.QueryString["productID"], null))
                {
                    productId = Request.QueryString["productID"];
                }

                Product product = DatabaseSystem.GetInstance().GetProductForId(productId);
                if (product == null)
                {
                    return;
                }

                FillDropDown();


                Categories.SelectedValue = product.categoryId;
                ProductTitle.Value       = product.title;
                ShortDesc.Value          = product.shortDescription;
                LongDesc.Value           = product.longDescription;
                Price.Value = product.price;
            }
        }
Example #2
0
 public ActionResult ProductView(int id = -1)
 {
     if (id == -1)
     {
         return(RedirectToAction("Index"));
     }
     ViewBag.product = DatabaseSystem.GetInstance().GetProductForId(id);
     return(View());
 }
Example #3
0
        public ActionResult LogOut()
        {
            foreach (Product p in ((User)Session["User"]).cart.contents)
            {
                DatabaseSystem.GetInstance().Add(p.ProductID, p.Quantity);
            }

            Session["User"] = null;
            return(RedirectToAction("Index", "Products"));
        }
Example #4
0
        public String Remove(int id, int quantity)
        {
            Product p = DatabaseSystem.GetInstance().GetProductForId(id);

            if (!((User)Session["User"]).cart.Remove(id, quantity))
            {
                return("Unable to remove " + p.Title + " from your cart");
            }

            if (!DatabaseSystem.GetInstance().Add(id, quantity))
            {
                return("Unable to remove " + p.Title + " from your cart");
            }

            return("Removed " + quantity + " of " + p.Title + " from your cart");
        }
Example #5
0
        private void FillDropDown()
        {
            List <Category> categoryList = DatabaseSystem.GetInstance().GetCategories();

            foreach (Category category in categoryList)
            {
                if (Categories.Items.FindByValue(category.categoryId) != null)
                {
                    continue;
                }

                ListItem item = new ListItem();
                item.Text  = category.title;
                item.Value = category.categoryId;
                Categories.Items.Add(item);
            }
        }
Example #6
0
        private void FillDropDown()
        {
            List <Product> products = DatabaseSystem.GetInstance().GetProducts();

            foreach (Product category in products)
            {
                if (Products.Items.FindByValue(category.categoryId) != null)
                {
                    continue;
                }

                ListItem item = new ListItem();
                item.Text  = category.title;
                item.Value = category.productId;
                Products.Items.Add(item);
            }
        }
Example #7
0
        public String Add(int id, int quantity)
        {
            if (Object.Equals(Session["User"], null))
            {
                Session["User"] = new User();
            }

            Product p = DatabaseSystem.GetInstance().GetProductForId(id);

            if (!DatabaseSystem.GetInstance().Remove(id, quantity))
            {
                return("Unable to add " + p.Title + " to your cart");
            }

            ((User)Session["User"]).cart.Add(id, quantity);
            return("Added " + quantity + " of " + p.Title + " to your cart");
        }
Example #8
0
        public ActionResult Register(User user)
        {
            User u = DatabaseSystem.GetInstance().GetUserForId(user.Username);

            if (u != null)
            {
                ViewBag.error = "Username already taken";
                return(View("Index"));
            }
            else if (!DatabaseSystem.GetInstance().RegisterUser(user))
            {
                ViewBag.error = "Unable to save user information to database";
                return(View("Index"));
            }

            Session["User"] = user;
            return(RedirectToAction("Index", "Products"));;
        }
Example #9
0
        public ActionResult LogIn(String username, String password)
        {
            User u = DatabaseSystem.GetInstance().AuthenticateUser(username, password);

            if (!Object.Equals(u, null))
            {
                if (!Object.Equals(Session["User"], null))
                {
                    u.ImportCart(((User)Session["User"]).cart);
                }

                Session["User"] = u;
                return(RedirectToAction("Index", "Products"));
            }

            ViewBag.error = "Username or password is incorrect";
            return(View());
        }
Example #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String productId = Request.QueryString["productID"];

            if (!loaded)
            {
                loaded = true;
                //confirm success
                if (DatabaseSystem.GetInstance().DeleteProduct(productId))
                {
                    status.Text = "Product Successfully deleted!";
                }
                else
                {
                    status.Text = "Unable to remove product!";
                }
            }
        }
Example #11
0
        protected void Upload_Image_Click(object sender, EventArgs e)
        {
            String jquery;
            String message = null;

            String imageUrl  = Server.MapPath("~/" + "images/product_images/" + File_Upload_Image.FileName);
            String productId = Products.SelectedValue;


            if (File_Upload_Image.HasFile)
            {
                try
                {
                    File_Upload_Image.SaveAs(imageUrl);

                    //save image info to database here
                    if (DatabaseSystem.GetInstance().UploadImage(productId, imageUrl))
                    {
                        message = "Successfully uploaded image!";
                    }
                }
                catch (Exception)
                {
                    message = "Unable to upload image!";
                }
            }
            else
            {
                message = "Unable to upload image!";
            }


            jquery = @"<script>
                $(function() {
                 

               bootbox.alert('" + message + @"', function() {});
                
                });
                </script>";

            Upload_Status.Controls.Add(new LiteralControl(jquery));
        }
Example #12
0
        protected void Edit_Click(object sender, EventArgs e)
        {
            String message;
            String msgTitle;
            String productId = Request.QueryString["productID"];

            Debug.WriteLine("Cat: " + Categories.SelectedValue + "\nTitle: " + ProductTitle.Value + "\nShort: " + ShortDesc.Value + "\nLong: " + LongDesc.Value + "Price: " + Price.Value);

            if (DatabaseSystem.GetInstance().UpdateProduct(new Product(
                                                               productId, Categories.SelectedValue,
                                                               ProductTitle.Value, ShortDesc.Value,
                                                               LongDesc.Value, Price.Value)))
            {
                message  = "Successfully updated product: " + ProductTitle.Value;
                msgTitle = "Update Successful";
            }
            else
            {
                message  = "Unable to update the product " + ProductTitle.Value;
                msgTitle = "Unable to Update Product";
            }

            String jquery = @"<script>
                    $(function() {
               
                            bootbox.dialog({
                                message: '" + message + @"',
                                title: '" + msgTitle + @"',
                                buttons: {
                                    main: {
                                        label: 'OK',
                                        callback: function(){
                                            window.location.href = 'DataManagement.aspx';
                                        }
                                    }
                                }
                            });
                    });
                    </script>";

            Viewport_Edit.Controls.Add(new LiteralControl(jquery));
        }
Example #13
0
        protected void Add_Click(object sender, EventArgs e)
        {
            String message;
            String msgTitle;
            String categoryId       = Categories.SelectedValue;
            String title            = ProductTitle.Value;
            String shortDescription = ShortDesc.Value;
            String longDescription  = LongDesc.Value;
            String price            = Price.Value;


            if (DatabaseSystem.GetInstance().AddProduct(new Product(categoryId, title, shortDescription, longDescription, price)))
            {
                message  = "Successfully added new product: " + title;
                msgTitle = "Product Added";
            }
            else
            {
                message  = "Unable to add new product: " + title;
                msgTitle = "Unable To Add Product";
            }

            String jquery = @"<script>
                    $(function() {
               
                            bootbox.dialog({
                                message: '" + message + @"',
                                title: '" + msgTitle + @"',
                                buttons: {
                                    main: {
                                        label: 'OK',
                                        callback: function(){
                                            window.location.href = 'DataManagement.aspx';
                                        }
                                    }
                                }
                            });
                    });
                    </script>";

            Viewport_Add.Controls.Add(new LiteralControl(jquery));
        }
        protected void Delete_Category_Click(object sender, EventArgs e)
        {
            String jquery;

            Viewport_Data.Controls.Clear();


            if (Categories.SelectedIndex > -1)
            {
                String selectedCatID = Categories.SelectedItem.Value;

                if (DatabaseSystem.GetInstance().DeleteCategory(selectedCatID))
                {
                    jquery = @"<script>
                    $(function() {
               
                            bootbox.alert('Successfully removed category " + Categories.SelectedItem.Text + " !', function() {});});</script>";

                    Categories.Items.Clear();
                    FillDropDown();
                }
                else
                {
                    jquery = @"<script>
                    $(function() {
               
                            bootbox.alert('Unable to remove category " + Categories.SelectedItem.Text + " !', function() {});});</script>";
                }
            }
            else
            {
                jquery = @"<script>
                $(function() {
               
                        bootbox.alert('Error, selected index is < 0 !', function() {});});</script>";
            }

            Viewport_Data.Controls.Add(new LiteralControl(jquery));
        }
Example #15
0
        public ActionResult Index(int id = -1)
        {
            List <Product>        products    = DatabaseSystem.GetInstance().GetProductsForCategory(id);
            List <SelectListItem> catDropDown = new List <SelectListItem>();

            catDropDown.Add(new SelectListItem {
                Value = "-1", Text = "All"
            });
            foreach (Category c in DatabaseSystem.GetInstance().GetCategories())
            {
                catDropDown.Add(new SelectListItem {
                    Value = String.Format("{0}", c.CategoryID),
                    Text  = c.Title
                });
            }

            ViewBag.categories = catDropDown;
            ViewBag.products   = products;


            return(View());
        }
        protected void Submit_Click(object sender, EventArgs e)
        {
            Viewport_Data.Controls.Clear();

            //get category id

            string selectedCatID;


            if (Categories.SelectedIndex > -1)
            {
                selectedCatID = Categories.SelectedItem.Value;
            }
            else
            {
                String error = @"<script>
                $(function() {
               
                        bootbox.alert('Error, selected index is < 0 !', function() {});});</script>";


                Viewport_Data.Controls.Add(new LiteralControl(error));

                return;
            }


            //get all the rows with the selected category ID from SQL...


            //Jquery script, method chaining is used. Bootbox is a 3rd party bootstrap + jqeury library
            String jquery = @"<script>
                $(function() {

                    var table = $('#table_id').DataTable();

                    $('#table_id').on('click', 'i.delete', function(e) {
                        var id = $(this).closest('tr').data('product_id');
                        window.location.href = 'DeleteProduct.aspx/?productID=' + id;             
           
                    }).on('click', 'i.edit', function(e) {
                        var id = $(this).closest('tr').data('product_id');
                        window.location.href = 'EditProduct.aspx/?productID=' + id; 
                    })
                });
                </script>";

            //construct the table in parts and combine them


            //construct table head. @ is used to allow concatenation of string with newline
            String tableHead = @"<table id='table_id' class='table table-condensed table-bordered table-striped table-hover'>
                <thead>
                    <tr>
                        <th>Image</th>
                        <th>Product ID</th>
                        <th>Category ID</th>
                        <th>Title</th>
                        <th>Short Description</th>
                        <th>Long Description</th>
                        <th>ImageURL</th>
                        <th>Price</th>
                        <th width='50'>&nbsp;</th>
                    </tr>
                </thead>
                <tbody>";


            //construct table body(rows)
            String tableBody = "";

            List <Product> products = DatabaseSystem.GetInstance().GetProductsForCategory(selectedCatID);

            foreach (Product product in products)
            {
                String imgUrl = product.imgUrl == null ? "No Image Found" : product.imgUrl;

                tableBody = tableBody + @"
                  <tr id='" + product.productId + "' data-product_id='" + product.productId + @"'>
                <td width='100px'><img src='" + product.imgUrl + @"' style='width: 100px; height: 100px' /></td>
                     <td>" + product.productId + @"</td>
                     <td>" + product.categoryId + @"</td>
                     <td>" + product.title + @"</td>
                     <td>" + product.shortDescription + @"</td>
                     <td>" + product.longDescription + @"</td>
                     <td>" + imgUrl + @"</td>
                     <td>" + product.price + @"</td>
                     <td><span style='cursor:pointer'><i class='fa fa-remove delete'></i></br><i class='fa fa-pencil-square-o edit'></i></span></td>
                  </tr>";
            }

            //construct table foot
            String tableFoot = "</tbody></table>";

            //combine all table parts
            String table = tableHead + tableBody + tableFoot;

            //Combine Jquery and the table to render on the browser
            String html = jquery + table;

            //add to the dynamic panel
            Viewport_Data.Controls.Add(new LiteralControl(html));
        }