コード例 #1
0
        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());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public IActionResult EditStock(string value)
        {
            BloodStock           bloodStock           = context.BloodStock.Find(int.Parse(value));
            ManageStockViewModel manageStockViewModel = new ManageStockViewModel(bloodStock);

            return(View(manageStockViewModel));
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            // using (var conte)
            BloodStock bloodStock = db.BloodStocks.Find(id);

            db.BloodStocks.Remove(bloodStock);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 //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);
 }
コード例 #6
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));
 }
コード例 #7
0
        public ActionResult Create([Bind(Include = "BloodListId,BloodName")] BloodStock bloodStock)
        {
            if (ModelState.IsValid)
            {
                db.BloodStocks.Add(bloodStock);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bloodStock));
        }
コード例 #8
0
        // 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));
        }
コード例 #9
0
 public void UpdateBloodDonation(BloodStock stock)
 {
     context.Entry(stock).State = EntityState.Modified;
 }
コード例 #10
0
 public async Task Update(BloodStock item)
 {
     _context.Entry(item).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
コード例 #11
0
 public void Delete(BloodStock item)
 {
     _context.BloodStock.Remove(item);
 }
コード例 #12
0
 public async Task Add(BloodStock item)
 {
     await _context.BloodStock.AddAsync(item);
 }
コード例 #13
0
 public ManageStockViewModel(BloodStock bloodStock)
 {
     Id         = bloodStock.Id;
     BloodGroup = bloodStock.BloodGroup;
     Quantity   = bloodStock.Quantity;
 }