コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public MedicalEquipment Get(int id)
        {
            var result = new MedicalEquipment();

            try {
                result = context.MedicalEquipments.Single(x => x.Id == id);
            }catch (System.Exception)
            {
                throw;
            }
            return(result);
        }
コード例 #4
0
 public bool Save(MedicalEquipment entity)
 {
     try
     {
         context.Add(entity);
         context.SaveChanges();
     }
     catch (System.Exception)
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
 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);
 }
コード例 #7
0
        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));
        }
コード例 #8
0
 public bool Update(MedicalEquipment entity)
 {
     throw new System.NotImplementedException();
 }
コード例 #9
0
 public bool Update(MedicalEquipment entity)
 {
     return(this.medicalEquipmentRepository.Update(entity));
 }
コード例 #10
0
 public bool Save(MedicalEquipment entity)
 {
     return(this.medicalEquipmentRepository.Save(entity));
 }
コード例 #11
0
 public ActionResult Put([FromBody] MedicalEquipment medicalEquipment)
 {
     return(Ok(
                medicalEquipmentService.Update(medicalEquipment)
                ));
 }
コード例 #12
0
 public ActionResult Post([FromBody] MedicalEquipment medicalEquipment)
 {
     return(Ok(
                medicalEquipmentService.Save(medicalEquipment)
                ));
 }