Exemplo n.º 1
0
        // GET: SuplyProducts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SuplyProduct suplyProduct = db.SuplyProduct.Find(id);

            if (suplyProduct == null)
            {
                return(HttpNotFound());
            }
            return(View(suplyProduct));
        }
Exemplo n.º 2
0
        public ActionResult Create(int Id, [Bind(Include = "Id,Id_SuplyInvoice,Id_Product,Quantity,UnitCost,TotalAmount")] SuplyProduct suplyProduct)
        {
            if (ModelState.IsValid)
            {
                suplyProduct.Id_SuplyInvoice = Id;
                suplyProduct.UnitCost        = (decimal)suplyProduct.TotalAmount / (decimal)suplyProduct.Quantity;

                db.SuplyProduct.Add(suplyProduct);
                db.SaveChanges();


                SuplyInvoice SI = db.SuplyInvoice.Find(Id);
                SI.TotalAmount = db.SuplyProduct.Where(t => t.Id_SuplyInvoice == Id).Select(i => i.TotalAmount).Sum();
                db.SaveChanges();

                return(RedirectToAction("Index", routeValues: new { Id = Id }));
            }

            return(RedirectToAction("Index", routeValues: new { Id = Id }));
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int Id = 0, int Id2 = 0)
        {
            if (Id == 0 || Id2 == 0)
            {
                return(RedirectToAction("Index", "SuplyInvoices"));
            }



            SuplyProduct suplyProduct = db.SuplyProduct.Find(Id);

            db.SuplyProduct.Remove(suplyProduct);
            db.SaveChanges();
            SuplyInvoice SI = db.SuplyInvoice.Find(Id2);

            SI.TotalAmount = db.SuplyProduct.Where(t => t.Id_SuplyInvoice == Id).Select(i => i.TotalAmount).Sum();
            db.SaveChanges();



            return(RedirectToAction("Index", routeValues: new { Id = Id2 }));
        }