예제 #1
0
        public ActionResult Delete()
        {
            // Create New Objects.
            ShopDal             sdal = new ShopDal();
            NewProductViewModel npvm = new NewProductViewModel();
            NewProduct          np   = new NewProduct();
            int flag = 0;

            // The list of products from Db.
            List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>();

            // Take all the values the manger want to update.
            np.ProductId = Request.Form["newproduct.ProductId"].ToString();

            // find the product we are looking for by ProductId.
            foreach (NewProduct ob in objProduct)
            {
                if (np.ProductId == ob.ProductId)
                {
                    // remove the product we want form the list.
                    sdal.NewproductDB.Remove(ob);
                    sdal.SaveChanges();
                    flag = 1;
                }
            }
            if (flag == 0)
            {
                TempData["errorId2"] = "The Id Product is not in the list.";
            }
            return(View("MangerPanel"));
        }
예제 #2
0
        public ActionResult Submit()
        {
            NewProductViewModel npvm          = new NewProductViewModel();
            NewProduct          objNewProduct = new NewProduct();
            int flag = 0;

            // Take all the values the manger insert.
            objNewProduct.ProductName     = Request.Form["newproduct.ProductName"].ToString();
            objNewProduct.Price           = int.Parse(Request.Form["newproduct.Price"]);
            objNewProduct.InitialQuantity = Request.Form["newproduct.InitialQuantity"].ToString();
            objNewProduct.ProductId       = Request.Form["newproduct.ProductId"].ToString();

            ShopDal sdal = new ShopDal();

            List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>();

            // Check if the ProductId allready in use
            foreach (NewProduct ob in objProduct)
            {
                if (objNewProduct.ProductId == ob.ProductId)
                {
                    flag = 1;
                    TempData["Message"] = "Error This key is already in used";
                }
            }
            // if the ProductId is not in used save the new Product in Db
            if (ModelState.IsValid && flag == 0)
            {
                sdal.NewproductDB.Add(objNewProduct);
                sdal.SaveChanges();
                npvm.newproduct = new NewProduct();
            }
            else
            {
                // if the manger insert wrong values, save tha data and Present it again.
                npvm.newproduct = objNewProduct;
            }

            // send the new list to the web  , for the manger can show it.
            npvm.newproducts = sdal.NewproductDB.ToList <NewProduct>();
            return(View("MangerPanel", npvm));
        }
예제 #3
0
        public ActionResult Update(NewProduct obj)
        {
            ShopDal             sdal       = new ShopDal();
            NewProductViewModel npvm       = new NewProductViewModel();
            List <NewProduct>   objProduct = sdal.NewproductDB.ToList <NewProduct>();
            int flag = 0;

            // Take all the values the manger want to update.
            obj.ProductId       = Request.Form["newproduct.ProductId"].ToString();
            obj.InitialQuantity = Request.Form["newproduct.InitialQuantity"].ToString();

            //Check if the Id in the list.
            foreach (NewProduct ob in objProduct)
            {
                if (obj.ProductId == ob.ProductId)
                {
                    flag = 1;
                }
            }

            if (flag == 0)
            {
                TempData["errorId"] = "The Id Product is not in the list.";
                return(View("MangerPanel"));
            }

            // find the product we are looking for by ProductId.
            NewProduct np1 =
                (from x in sdal.NewproductDB
                 where x.ProductId == obj.ProductId
                 select x).ToList <NewProduct>()[0];

            // update the new Amount
            np1.InitialQuantity = obj.InitialQuantity;
            // Save the changes.
            sdal.SaveChanges();

            // return to the MangerPanel.
            return(View("MangerPanel"));
        }
예제 #4
0
        public ActionResult Submit()
        {
            ShopDal           sdal       = new ShopDal();
            Customer          cus        = new Customer();
            string            amount     = "";
            DateTime          TimeNow    = DateTime.Now;
            List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>();

            // Check if the object is Valid.
            if (ModelState.IsValid)
            {
                // check if the customer name is less than two letter's.
                if (Request.Form["name"].Length != 0 && Request.Form["name"].Length != 1 && Regex.IsMatch(Request["name"], @"^[a-zA-Z]+$"))
                {
                    // if not save the name.
                    cus.CustomerName = Request.Form["name"];
                }
                else
                {
                    TempData["error"] = "Insert Correct Name between 2 and 10 words.";
                    return(RedirectToAction("HomeWeb", TempData["error"]));
                }
                // save the id of the prodect the customer bought.
                string id = Request.Form["ko"];

                // Amount of product to buy 1-5.
                string Amount = Request.Form["testSelect"];

                foreach (NewProduct ob in objProduct)
                {
                    // find the id that we take from the list.
                    if (id == ob.ProductId)
                    {
                        // Save the name of the customer
                        cus.ProductName = ob.ProductName;
                        // Save the Amount
                        cus.Quantity = Amount;
                        //Subtract the Amount the customer bought from list.
                        amount = (int.Parse(ob.InitialQuantity) - int.Parse(Amount)).ToString();
                        // save the time is purchase
                        cus.Date = TimeNow.ToString();
                    }
                }

                // Check if it Ok
                if (ModelState.IsValid)
                {
                    // Add the Customer to Db.
                    sdal.CustomerDB.Add(cus);
                    sdal.SaveChanges();
                }

                // find the product , the custoemr bought
                NewProduct np1 =
                    (from x in sdal.NewproductDB
                     where x.ProductId == id
                     select x).ToList <NewProduct>()[0];

                // Update the new Amount of the Product.
                np1.InitialQuantity = amount;
                sdal.SaveChanges();

                // Return to the same page
                return(View("CustomerName"));
            }
            else
            {
                return(RedirectToAction("HomeWeb"));
            }
        }