/// <summary>
        /// Displays all products in the location's inventory. Accepts console input to manage product quantities.
        /// Product quantities can be increased or decreased according to input.
        /// </summary>
        /// <example>
        /// Example input:
        /// [Id] [Quantity], [Id] [Quantity], . . .
        /// 15 12, 301 -20, 400 30
        /// Increase quantity of product 15 by 12. Decrease quantity of product 301 by 20. Increase quantity of product 400 by 30.
        /// </example>
        public void ManageInventory()
        {
            try
            {
                CurrentLocation();
                Console.WriteLine("0:\tReturn");
                DisplayInventory();

                //Console input.
                Console.Write("\nExample: 142 12, 43 -20, 8890 30\nEnter [Id] [Quantity] of Products Separated By Commas:\n> ");
                var input = Console.ReadLine();
                Console.Clear();

                //0 : Return;
                if (input == "0")
                {
                    Continue();
                    return;
                }

                //Updates product quantities.
                var productsUpdated = new ProductDb().UpdateInventory(input, UI.Location.Id);
                Console.WriteLine("Inventory Updated.\n");
                foreach (var product in productsUpdated)
                {
                    Console.WriteLine(product);
                }
                Console.WriteLine();
                Continue();
            }
            catch (System.Exception)
            {
                CommandError();
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            // Get product with corresponding id
            Product p = await ProductDb.GetProductAsync(_context, id);

            return(View(p));
        }
示例#3
0
        public async Task <IActionResult> Delete(int id)
        {
            Product p =
                await ProductDb.GetProductAsync(_context, id);

            return(View(p));
        }
        public static Result EditProduct(ProductModel model)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var item = db.Products.Find(model.ProductID);
                    if (item != null)
                    {
                        item.ProductModelToProductMapExtension(model);

                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to edit Product"));
            }

            return(result);
        }
        public async Task <IActionResult> Edit(int id)
        {
            Product p = await ProductDb.GetProductByIdAsync(_context, id);

            // Pass product to view
            return(View(p));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Product> products = new List<Product>();
            using (ProductDb db = new ProductDb())
            {
                //Choose three random products
                products = db.Products.OrderBy(p => Guid.NewGuid()).Take(3).ToList();
            }
            foreach (Product p in products)
            {
                //Dynamically create links in the same style as other links on the homepage for the 3 randomly choosen products from above.
                HtmlGenericControl ColDiv = new HtmlGenericControl("div");
                ColDiv.Attributes["class"] = "col-md-4";
                HtmlGenericControl article = new HtmlGenericControl("article");
                article.Attributes["class"] = "Links";
                article.Attributes["style"] = "background-image:url(" + p.MainProductImage.ToString() + ");";
                HtmlGenericControl HoverDiv = new HtmlGenericControl("div");
                HoverDiv.Attributes["class"] = "hover";
                HtmlGenericControl h4 = new HtmlGenericControl("h4");
                h4.InnerText = p.ProductName;
                HtmlGenericControl p1 = new HtmlGenericControl("p");
                p1.InnerText = p.Description;
                HtmlGenericControl p2 = new HtmlGenericControl("p");
                p2.InnerHtml = "<a href='ProductDetails.aspx?ProductId="+p.ProductId+"' class='btn btn-info btn-sm'>Go</a>";
                HoverDiv.Controls.Add(h4);
                HoverDiv.Controls.Add(p1);
                HoverDiv.Controls.Add(p2);
                article.Controls.Add(HoverDiv);
                ColDiv.Controls.Add(article);
                RandomProducts.Controls.Add(ColDiv);

            }
        }//End Page Load
        public async Task <IActionResult> Edit(int id)
        {
            // Get product with corresponding id
            Product p = await ProductDb.GetSingleProductAsync(_context, id);

            // pass product to view
            return(View(p));
        }
示例#8
0
        public IActionResult Edit(int id)
        {
            //get the product by id
            Product p = ProductDb.GetProduct(context, id);

            //show it on the web page
            return(View(p));
        }
        public ProductMaintenanceView()
        {
            InitializeComponent();
            productDb = new ProductDb();
            productDb.GetProducts();

            lstBoxProducts.DataSource = productDb.Products;
        }
示例#10
0
        // GET: Product
        //gọi trang danh sách sản phẩm (product)
        public ActionResult Index()
        {
            var products = new ProductDb().List;

            TempData["products"] = products;
            TempData.Keep();
            return(View());
        }
示例#11
0
        public ActionResult ProductList()
        {
            //Lấy data từ ProductDb
            var products = new ProductDb().List;

            //truyền data sang view theo dạng Model
            return(View(products));
        }
        public async Task <IActionResult> Index()
        {
            // get all products out of the database
            List <Product> products = await ProductDb.ListProductsAsync(_context);

            // send list to view to be displayed
            return(View(products));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var product = await ProductDb.SelectProductAsync(_context, id);

            await ProductDb.DeleteProductAsync(_context, product);

            return(RedirectToAction(nameof(Index)));
        }
示例#14
0
        private void FrmUpsell_Load(object sender, EventArgs e)
        {
            lblMessage.Text = "Any additional items?";
            PopulateCurrentOrderList(existingOrder.Products.ToList());
            List <Products> desserts = ProductDb.GetDesserts();

            PopulateProductsList(desserts);
        }
示例#15
0
        /// <summary>
        /// Removes an item from the shopping cart
        /// </summary>
        /// <param name="id"> Id of the product to remove </param>
        public async Task <IActionResult> Remove(int id, string prevUrl)
        {
            Products p = await ProductDb.GetProductAsync(_context, id);

            CookieHelper.RemoveProductFromCart(_httpContext, p);

            // redirect to previous page
            return(Redirect(prevUrl));
        }
示例#16
0
        // provide 2 additional methods
        public void Fill()
        {
            List <Product> products = ProductDb.GetProducts();

            foreach (Product product in products)
            {
                base.Add(product);
            }
        }
示例#17
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            Product p = await ProductDb.GetProductAsync(_context, id);

            await ProductDb.DeleteProductAsync(_context, p);

            TempData["Message"] = $"{p.Title} was deleted successfully";
            return(RedirectToAction("Index"));
        }
示例#18
0
 public ItemInfo GetItemInfo(string id)
 {
     return(new ItemInfo()
     {
         Item = ProductDb.Get().Pro_Item.Where(q => q.Id == id).First(),
         ItemSkuList = ProductDb.Get().Pro_ItemSku.Where(q => q.ItemId == id && q.IsOnSale == true).ToList(),
         ImageList = ProductDb.Get().Pro_ItemImage.Where(q => q.ItemId == id).ToList()
     });
 }
示例#19
0
        /// <summary>
        /// Adds a product to the shopping cart
        /// </summary>
        /// <param name="id">The id of the product to add</param>
        /// <returns></returns>
        public async Task <IActionResult> Add(int id)
        {
            Product p = await ProductDb.GetSingleProductAsync(_context, id);

            CookieHelper.AddProductToCart(_httpContext, p);

            // Redirect back to previous page
            return(RedirectToAction("Index", "Product"));
        }
示例#20
0
        /// <summary>
        /// Displays all <c>Product</c> which reference the current <c>Location</c> in the database.
        /// </summary>
        public void DisplayInventory()
        {
            ICollection <Product> products = new ProductDb().GetProducts(UI.Location.Id);

            foreach (var product in products)
            {
                Console.WriteLine(product);
            }
        }
示例#21
0
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                await ProductDb.Create(product, _context); //add to database

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                await ProductDb.EditProductAsync(_context, product);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
示例#23
0
        // GET: Admin/Product
        public ActionResult Index(string searchString = "", int categoryID = 0)
        {
            var categories = new CategoryDb().GetCategories(ref err, 0);

            ViewBag.categoryID = new SelectList(categories, "ID", "Name");
            //viet code de lay products list.
            var products = new ProductDb().GetProducts(ref err, searchString, categoryID);

            return(View(products));
        }
        /// <summary>
        /// Adds a product to the shopping cart
        /// </summary>
        /// <param name="id">The id of the product to add</param>
        /// <returns></returns>
        public async Task <IActionResult> Add(int id) // Id of the product to add
        {
            // Get product from the DB
            Product p = await ProductDb.GetProductByIdAsync(_context, id);

            CookieHelper.AddProductToCart(p, _httpContext);

            // Redirect back to previous page
            return(RedirectToAction("Index", "Product"));
        }
        public ManageProducts()
        {
            InitializeComponent();

            _database = new ProductDb();

            var products = _database.GetProducts();

            lstData.ItemsSource = products;
        }
        public async Task <IActionResult> Edit(int id)
        {
            var product = await ProductDb.SelectProductAsync(_context, id);

            if (product == null)
            {
                return(NotFound());
            }
            return(View(product));
        }
        public async Task <IActionResult> Edit(Product p)
        {
            if (ModelState.IsValid)
            {
                await ProductDb.EditProductAsync(_context, p);

                ViewData["Message"] = "Product updated successfully";
            }
            return(View(p));
        }
示例#28
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            Product p =
                await ProductDb.GetProductAsync(_context, id);

            _context.Entry(p).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            TempData["Message"] = $"{p.Title} was deleted";
            return(RedirectToAction("Index"));
        }
示例#29
0
        public async Task <IActionResult> Add(int id, string prevUrl)
        {
            Product p = await ProductDb.GetProductAsync(_context, id);

            CookieHelper.AddProductToCart(_httpContext, p);

            TempData["Message"] = p.Title + " added successfully";

            // Redirect back to previous page
            return(Redirect(prevUrl));
        }
        public async void OnDeleteClicked(object sender, EventArgs args)
        {
            productDb = new ProductDb();
            bool accepted = await DisplayAlert("Confirm", "Are you Sure ?", "Yes", "No");

            if (accepted)
            {
                productDb.DeleteProduct(product);
            }
            await Navigation.PushAsync(new ManageProducts());
        }
示例#31
0
        public IActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                ProductDb.AddProduct(_context, product);
                return(RedirectToAction("Index"));
            }

            //return model back to view with errors
            return(View());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SignedInUser.Text = null;
                NumberInCart();
                //Check if a Customer is signed in
                if (Request.Cookies[FormsAuthentication.FormsCookieName] == null)
                {
                    SignedInUser.Visible = false;
                    hlSignIn.Visible = true;
                    hlRegister.Visible = true;
                }
                else
                {
                    // if someone is signed in it takes the information from the Auth Cookie and uses it to retrieve the customer with that user name.
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                    Customer c = ReturnCustomer(ticket.Name);
                    //Displays their first and last name in the navigation
                    SignedInUser.Text = string.Format("Hello, {0} <span class='caret'></span>", c.FirstName + " " + c.Lastname);
                    SignedInUser.Visible = true;
                    hlSignIn.Visible = false;
                    hlRegister.Visible = false;
                }
                //if remember cookie exists fill in information in sign in form
                if (Request.Cookies["Remember"] != null)
                {
                    chkRemember.Checked = true;
                    txtUsername.Text = Request.Cookies["Remember"]["Username"];
                }

            }

            using (ProductDb db = new ProductDb())
            {
                Categories = db.ProductCategorys.Include("SubCategories").ToList();

                foreach (ProductCategory pc in Categories)
                {
                    //Dynamically create a link for each Product Category in the database
                    HtmlGenericControl li = new HtmlGenericControl("li");
                    li.Attributes["class"] = "dropdown";
                    HyperLink link = new HyperLink();
                    //link.NavigateUrl = string.Format("~/Products.aspx?CategoryID={0}", pc.CatergoryID);
                    link.NavigateUrl = "#";
                    link.ID = "Category" + pc.CatergoryID.ToString();
                    link.Text = pc.CategoryType + " <span class='caret'></span>";
                    link.CssClass = "dropdown-toggle";
                    link.Attributes["role"] = "button";
                    link.Attributes["data-toggle"] = "dropdown";
                    link.Attributes["aria-expanded"] = "false";
                    HtmlGenericControl span = new HtmlGenericControl("span");
                    span.Attributes["class"] = "caret";
                    li.Controls.Add(link);
                    HtmlGenericControl ul = new HtmlGenericControl("ul");
                    ul.Attributes["class"] = "dropdown-menu";
                    ul.Attributes["role"] = "menu";
                    li.Controls.Add(ul);
                    //For each Product Category create a dropdown with links for each Sub Category in the database
                    foreach (ProductSubCategory psc in pc.SubCategories)
                    {
                        HtmlGenericControl li2 = new HtmlGenericControl("li");
                        HyperLink Sublink = new HyperLink();
                        Sublink.NavigateUrl = string.Format("~/Products.aspx?SubCategoryID={0}", psc.SubCatergoryID);
                        Sublink.Text = psc.SubCategoryType;
                        Sublink.ID = "SubCategory" + psc.SubCatergoryID.ToString();
                        li2.Controls.Add(Sublink);
                        ul.Controls.Add(li2);
                    }
                    NavList.Controls.Add(li);
                }

            }
        }
 //Create a delegate and event
 public void Delegate(int customerid)
 {
     CustomerLogin cust;
     using (ProductDb db = new ProductDb())
     {
         //gets the customer using the id.
         cust = db.CustomerLogins.SingleOrDefault(c => c.Customer.CustomerId == customerid);
         if (cust != null)
         {
             SignInDelegate sd = new SignInDelegate(CustomerAlert);
             sd += UpdateNavbar;
             sd += AuthCookie;
             SignInEvent = sd;
             SignInEvent(cust.UserName);
         }
     }
 }
 public void SortProducts( string s)
 {
     using (var db = new ProductDb())
     {
         
         var p = from a in db.Products select a;
         switch (s)
         {
             case "0":
                 p = p.OrderBy(a => a.ProductName);
                 break;
             case "1":
                 p = p.OrderBy(a => a.Price);
                 break;
             case "2":
                 p = p.OrderByDescending(a => a.Price);
                 break;
             case "3":
                 p = p.OrderByDescending(a => a.Stock);
                 break;
             default:
                 p = p.OrderBy(a => a.ProductName);
                 break;
         }
         foreach (Product pr in p)
         {
             products.Add(pr);
         }
     }
 }
        //returns a customer from the user name of the customer
        public Customer ReturnCustomer(string n)
        {
            using (ProductDb db = new ProductDb())
            {
                Customer customer = new Customer();
                CustomerLogin cl = db.CustomerLogins.Include(c => c.Customer).SingleOrDefault(c => c.UserName == n);
                if (cl != null)
                    customer = db.Customers.SingleOrDefault(cust => cust.CustomerId == cl.Customer.CustomerId);

                return customer;
            }
        }