public IHttpActionResult PutPurchaseRequestLine(int id, PurchaseRequestLine purchaseRequestLine) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchaseRequestLine.Id) { return(BadRequest()); } db.Entry(purchaseRequestLine).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PurchaseRequestLineExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public JsonResponse edit(PurchaseRequestLine line) { if (line == null) { return new JsonResponse { Error = "-4", Message = "Line item is null", Result = "failed" } } ; if (!ModelState.IsValid) { return new JsonResponse { Error = "-3", Message = "the item is not valid", Result = "Failed" } } ; var l = db.PurchaseLines.Find(line.Id); l.Price = line.Price; l.Product = line.Product; l.ProductId = line.ProductId; l.PurchaseRequest = line.PurchaseRequest; l.PurchaseRequestId = line.PurchaseRequestId; l.Quantity = line.Quantity; db.SaveChanges(); Add(l); return(new JsonResponse()); }
public JsonResponse delete(PurchaseRequestLine line) { if (line == null) { return new JsonResponse { Error = "-4", Message = "Line item is null", Result = "failed" } } ; if (!ModelState.IsValid) { return new JsonResponse { Error = "-3", Message = "the item is not valid", Result = "Failed" } } ; PurchaseRequestLine l = db.PurchaseLines.Find(line.Id); PurchaseRequest request = db.Requests.Find(l.PurchaseRequestId); request.Price -= l.Price; db.PurchaseLines.Remove(l); db.SaveChanges(); return(new JsonResponse()); } } }
public ActionResult DeleteConfirmed(int id) { PurchaseRequestLine purchaseRequestLine = db.PurchaseRequestLines.Find(id); db.PurchaseRequestLines.Remove(purchaseRequestLine); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,PurchaseRequestId,ProductId,Quanity,Price")] PurchaseRequestLine purchaseRequestLine) { if (ModelState.IsValid) { db.Entry(purchaseRequestLine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseRequestLine)); }
public IHttpActionResult GetPurchaseRequestLine(int id) { PurchaseRequestLine purchaseRequestLine = db.PurchaseRequestLines.Find(id); if (purchaseRequestLine == null) { return(NotFound()); } return(Ok(purchaseRequestLine)); }
public ActionResult Create([Bind(Include = "Id,PurchaseRequestId,ProductId,Quanity,Price")] PurchaseRequestLine purchaseRequestLine) { if (ModelState.IsValid) { db.PurchaseRequestLines.Add(purchaseRequestLine); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseRequestLine)); }
public IHttpActionResult PostPurchaseRequestLine(PurchaseRequestLine purchaseRequestLine) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PurchaseRequestLines.Add(purchaseRequestLine); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = purchaseRequestLine.Id }, purchaseRequestLine)); }
public IHttpActionResult DeletePurchaseRequestLine(int id) { PurchaseRequestLine purchaseRequestLine = db.PurchaseRequestLines.Find(id); if (purchaseRequestLine == null) { return(NotFound()); } db.PurchaseRequestLines.Remove(purchaseRequestLine); db.SaveChanges(); return(Ok(purchaseRequestLine)); }
// GET: PurchaseRequestLines/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PurchaseRequestLine purchaseRequestLine = db.PurchaseRequestLines.Find(id); if (purchaseRequestLine == null) { return(HttpNotFound()); } return(View(purchaseRequestLine)); }
public void Add(PurchaseRequestLine line) { PurchaseRequest request = db.Requests.Find(line.PurchaseRequestId); request.Price = 0; List <PurchaseRequestLine> lines = db.PurchaseLines.ToList(); foreach (PurchaseRequestLine item in lines) { if (item.PurchaseRequestId == request.Id) { request.Price += item.Price; } } }
public JsonResponse create(PurchaseRequestLine line) { if (line == null) { return new JsonResponse { Error = "-4", Message = "Line item is null", Result = "failed" } } ; if (!ModelState.IsValid) { return new JsonResponse { Error = "-3", Message = "the item is not valid", Result = "Failed" } } ; db.PurchaseLines.Add(line); Add(line); db.SaveChanges(); return(new JsonResponse()); }