public async Task <ActionResult <BloodStock> > DeleteBloodStock(int id) { //var bloodStock = await _repository.GetById(id); //if (bloodStock == null) //{ // return NotFound(); //} //_repository.Delete(bloodStock); //return bloodStock; if (!await _repository.Exists(id)) { return(NotFound()); } BloodStock bloodStockEntity2Delete = await _repository.GetById(id); if (bloodStockEntity2Delete == null) { return(NotFound()); } _repository.Delete(bloodStockEntity2Delete); if (!await _repository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }
public IActionResult EditStock(ManageStockViewModel manageStockViewModel, string radioButton, string amountToUpdate) { if (ModelState.IsValid) { BloodStock bloodStockToUpdate = context.BloodStock.Find(manageStockViewModel.Id); if (radioButton == "Increase") { bloodStockToUpdate.Quantity = manageStockViewModel.Quantity + int.Parse(amountToUpdate); } else { if (manageStockViewModel.Quantity < int.Parse(amountToUpdate)) { ModelState.AddModelError("AmountToUpdate", "Please enter a quantity less than " + manageStockViewModel.Quantity + " units"); return(View(manageStockViewModel)); } bloodStockToUpdate.Quantity = manageStockViewModel.Quantity - int.Parse(amountToUpdate); } context.BloodStock.Update(bloodStockToUpdate); context.SaveChanges(); TempData["msg"] = "Blood Group: " + bloodStockToUpdate.BloodGroup + " updated to " + bloodStockToUpdate.Quantity + " units."; return(Redirect("/ManageStock")); } return(View(manageStockViewModel)); }
public IActionResult EditStock(string value) { BloodStock bloodStock = context.BloodStock.Find(int.Parse(value)); ManageStockViewModel manageStockViewModel = new ManageStockViewModel(bloodStock); return(View(manageStockViewModel)); }
public ActionResult DeleteConfirmed(int id) { // using (var conte) BloodStock bloodStock = db.BloodStocks.Find(id); db.BloodStocks.Remove(bloodStock); db.SaveChanges(); return(RedirectToAction("Index")); }
//method to add new blood stock info internal int AddBloodStock(BloodStock bloodstock) { using (var bbContext = new BloodBankDBEntities()) { bbContext.BloodStocks.Add(bloodstock); bbContext.SaveChanges(); } return(0); }
public ActionResult Edit([Bind(Include = "BloodListId,BloodName")] BloodStock bloodStock) { if (ModelState.IsValid) { db.Entry(bloodStock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bloodStock)); }
public ActionResult Create([Bind(Include = "BloodListId,BloodName")] BloodStock bloodStock) { if (ModelState.IsValid) { db.BloodStocks.Add(bloodStock); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bloodStock)); }
// GET: BloodStocks/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BloodStock bloodStock = db.BloodStocks.Find(id); if (bloodStock == null) { return(HttpNotFound()); } return(View(bloodStock)); }
public void UpdateBloodDonation(BloodStock stock) { context.Entry(stock).State = EntityState.Modified; }
public async Task Update(BloodStock item) { _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public void Delete(BloodStock item) { _context.BloodStock.Remove(item); }
public async Task Add(BloodStock item) { await _context.BloodStock.AddAsync(item); }
public ManageStockViewModel(BloodStock bloodStock) { Id = bloodStock.Id; BloodGroup = bloodStock.BloodGroup; Quantity = bloodStock.Quantity; }