Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            UsedProducts usedProducts = db.UsedProducts.Find(id);

            db.UsedProducts.Remove(usedProducts);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        // GET: UsedProducts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UsedProducts usedProducts = db.UsedProducts.Find(id);

            if (usedProducts == null)
            {
                return(HttpNotFound());
            }
            return(View(usedProducts));
        }
Ejemplo n.º 3
0
        public ActionResult UpdateVolume(int?id)
        {
            ViewBag.EmployeesID = db.Employees.ToList();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UsedProducts stock = db.UsedProducts.Find(id);

            if (stock == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EmployeesID = new SelectList(db.Employees, "EmployeesID", "FullName", stock.EmployeesID);
            return(View(stock));
        }
Ejemplo n.º 4
0
        public ActionResult UpdateVolume([Bind(Exclude = "dateModified")] UsedProducts stock, string newVolume)
        {
            ////TODO : Add Validation to prevent negative values to be updated
            ViewBag.EmployeesID = new SelectList(db.Employees, "EmployeesID", "FullName", stock.EmployeesID);
            int s = int.Parse(newVolume);

            //if (!(newVolume == null))
            //{
            //    s= (int)newVolume;
            //}
            if (ModelState.IsValid)
            {
                if (s <= 0)
                {
                    return(Content("<script language='javascript' type='text/javascript'>alert('Couldnt update Volume as new Volume is 0 ! Go Back and try Agains!');</script>"));
                }
                else
                if (s > stock.Usedvolume)
                {
                    return(Content("<script language='javascript' type='text/javascript'>alert('Couldnt update Volume as new Volume is Greater than Current Volume ! Go Back and try Agains!');</script>"));
                }
                else
                {
                    stock.dateModified    = DateTime.Now;
                    stock.Usedvolume      = stock.Usedvolume - s;
                    db.Entry(stock).State = EntityState.Modified;

                    var newupdtmdl = new UpdateVolume();
                    newupdtmdl.dateUpdated    = DateTime.Now;
                    newupdtmdl.EmployeesID    = stock.EmployeesID;
                    newupdtmdl.newVolume      = s;
                    newupdtmdl.UsedProductsID = stock.UsedProductsID;
                    newupdtmdl.Employee       = db.Employees.Find(stock.EmployeesID);
                    newupdtmdl.UsedProducts   = db.UsedProducts.Find(stock.UsedProductsID);

                    db.UpdateVolume.Add(newupdtmdl);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(stock));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Exclude = "Usedqty,Usedvolume,dateAdded,dateModified")] UsedProducts usedProducts)
        {
            var ogStock = db.Stocks.Find(usedProducts.StockID);

            if (ModelState.IsValid)
            {
                usedProducts.Usedvolume   = ogStock.volume;
                usedProducts.Usedqty      = 1;
                ogStock.qty               = ogStock.qty - 1;
                db.Entry(ogStock).State   = EntityState.Modified;
                usedProducts.dateAdded    = DateTime.Now;
                usedProducts.dateModified = new DateTime();
                db.UsedProducts.Add(usedProducts);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StockID     = new SelectList(db.Stocks, "StockID", "Title", usedProducts.StockID);
            ViewBag.EmployeesID = new SelectList(db.Employees, "EmployeesID", "FullName", usedProducts.EmployeesID);
            return(View(usedProducts));
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            List <Product> productsList = new List <Product>();

            Console.Write("Enter the number of products: ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                //product sequence number
                Console.WriteLine("Product #{0}", i + 1);
                //Product type
                Console.Write("Common, used or imported (c/u/i): ");
                char productType = char.Parse(Console.ReadLine());
                //Name
                Console.Write("Name: ");
                string name = Console.ReadLine();
                //Price
                Console.Write("Price: ");
                double price = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

                Product product;

                switch (productType)
                {
                case 'c':
                    product = new Product(name, price);
                    break;

                case 'u':
                    //Asking for the manufacture date of the product
                    Console.Write("Manufacture date (DD/MM/YYYY): ");
                    DateTime manufactureDate = DateTime.Parse(Console.ReadLine());
                    //So, we instantiate the used product
                    product = new UsedProducts(name, price, manufactureDate);
                    break;

                case 'i':
                    //Asking for the customs fee
                    Console.Write("Customs fee: ");
                    double customsFee = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                    //So, we instantiate the imported product
                    product = new ImportedProducts(name, price, customsFee);
                    break;

                default:
                    Console.Write("Invalid type. Please choose a common, used or imported product (c/u/i): ");
                    productType = char.Parse(Console.ReadLine());
                    return;
                }

                productsList.Add(product);
            }

            //Resume
            Console.WriteLine("PRICE TAGS: ");
            foreach (Product prod in productsList)
            {
                Console.WriteLine(prod.PriceTag());
            }
        }