public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Quantity")] MedicalEquipment medicalEquipment) { if (id != medicalEquipment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(medicalEquipment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedicalEquipmentExists(medicalEquipment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(medicalEquipment)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Quantity")] MedicalEquipment medicalEquipment) { if (ModelState.IsValid) { _context.Add(medicalEquipment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(medicalEquipment)); }
public MedicalEquipment Get(int id) { var result = new MedicalEquipment(); try { result = context.MedicalEquipments.Single(x => x.Id == id); }catch (System.Exception) { throw; } return(result); }
public bool Save(MedicalEquipment entity) { try { context.Add(entity); context.SaveChanges(); } catch (System.Exception) { return(false); } return(true); }
public bool Delete(int id) { try { var result = new MedicalEquipment(); result = context.MedicalEquipments.Single(x => x.Id == id); context.Remove(result); context.SaveChanges(); return(true); } catch (System.Exception) { throw; } }
public bool Update(MedicalEquipment entity) { try{ var newMedicalEquipment = context.MedicalEquipments.Single(x => x.Id == entity.Id); newMedicalEquipment.Id = entity.Id; newMedicalEquipment.StateDescription = entity.StateDescription; newMedicalEquipment.Brand = entity.Brand; newMedicalEquipment.Name = entity.Name; context.Update(newMedicalEquipment); context.SaveChanges(); } catch (System.Exception) { return(true); } return(false); }
public JsonResult SuggestOrder(int?id) { // From all equipments, select equipment that wasn't recently ordered and that there's avaialable supply and we have the least of // Getting all equipments that weren't ordered recently in order of the quantity the given hospital currently have var relevantEquipment = _context.MedicalEquipment .Where(e => !_recentlyOrdered.Contains(e.Id)) .Include(e => e.medicalEquipmentSupplies) .OrderBy(e => e.medicalEquipmentSupplies.Where(mes => mes.HospitalId == id).FirstOrDefault().SupplyQuantity) .ToList(); MedicalEquipment suggestedOrder = null; int available = 0; // Getting an equipment with available supply foreach (var equipment in relevantEquipment) { available = (int)AvailableSupply(equipment.Id).Value; if (available > 0) { suggestedOrder = equipment; break; } } ; if (suggestedOrder == null || available == 0) { return(null); } var suggestedMedicalSupply = suggestedOrder.medicalEquipmentSupplies.Where(mes => mes.HospitalId == id).FirstOrDefault(); var suggestion = new { EquipmentId = suggestedOrder.Id, EquipmentName = suggestedOrder.Name, CurrentQuantity = suggestedMedicalSupply == null ? 0 : suggestedMedicalSupply.SupplyQuantity, AvailableSupply = available }; return(Json(suggestion)); }
public bool Update(MedicalEquipment entity) { throw new System.NotImplementedException(); }
public bool Update(MedicalEquipment entity) { return(this.medicalEquipmentRepository.Update(entity)); }
public bool Save(MedicalEquipment entity) { return(this.medicalEquipmentRepository.Save(entity)); }
public ActionResult Put([FromBody] MedicalEquipment medicalEquipment) { return(Ok( medicalEquipmentService.Update(medicalEquipment) )); }
public ActionResult Post([FromBody] MedicalEquipment medicalEquipment) { return(Ok( medicalEquipmentService.Save(medicalEquipment) )); }