public ActionResult Edit([Bind(Include = "ID,RepairID,Name,CatalogNumber,PurchaseAmount,PurchaseDate,SalesAmount,SalesDate")] PartModels partModels)
        {
            if (ModelState.IsValid)
            {
                var oldPart = db.Parts.Where(b => b.ID == partModels.ID).AsNoTracking().SingleOrDefault();
                db.Parts.Attach(partModels);
                db.Entry(partModels).State = EntityState.Modified;
                db.SaveChanges();



                var result = db.Reapirs.SingleOrDefault(b => b.Id == partModels.RepairID);
                if (result != null)
                {
                    result.RepairAmount = result.RepairAmount + (partModels.PurchaseAmount - oldPart.PurchaseAmount);
                    db.Reapirs.Attach(result);
                    db.Entry(result).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            ViewBag.RepairID = new SelectList(db.Reapirs, "Id", "Name", partModels.RepairID);
            return(View(partModels));
        }
        public ActionResult DeleteConfirmed()
        {
            int?id = Int32.Parse(Request.Form.Get("id"));

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PartModels partModels = db.Parts.Find(id);

            var result = db.Reapirs.SingleOrDefault(b => b.Id == partModels.RepairID);

            if (result != null)
            {
                result.RepairAmount = result.RepairAmount - (partModels.PurchaseAmount);
                db.Reapirs.Attach(result);
                db.Entry(result).State = EntityState.Modified;
                db.SaveChanges();
            }

            db.Parts.Remove(partModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            PartModels partModels = db.Parts.Find(id);

            db.Parts.Remove(partModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "ID,CarID,Name,CatNo,PurchasePrice,PurchaseSale,PurchaseDate,SaleDate")] PartModels partModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(partModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(partModels));
 }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "ID,CarID,Name,CatNo,PurchasePrice,PurchaseSale,PurchaseDate,SaleDate")] PartModels partModels)
        {
            if (ModelState.IsValid)
            {
                db.Parts.Add(partModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(partModels));
        }
Beispiel #6
0
        // GET: Part/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartModels partModels = db.Parts.Find(id);

            if (partModels == null)
            {
                return(HttpNotFound());
            }
            return(View(partModels));
        }
        public ActionResult Details()
        {
            int?id = Int32.Parse(Request.Form.Get("id"));

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartModels partModels = db.Parts.Find(id);

            if (partModels == null)
            {
                return(HttpNotFound());
            }
            return(View(partModels));
        }
        public ActionResult EditPart()
        {
            int?id = Int32.Parse(Request.Form.Get("id"));

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartModels partModels = db.Parts.Find(id);

            if (partModels == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RepairID = new SelectList(db.Reapirs.Where(i => i.Id == partModels.RepairID), "Id", "Name", partModels.RepairID);
            return(View(partModels));
        }