Пример #1
0
        public async Task <IActionResult> Order(int HospitalId, int EquipmentId, int Quantity)
        {
            MedicalEquipmentSupply supply = _context.MedicalEquipmentSupply
                                            .FirstOrDefault(mes => mes.HospitalId == HospitalId && mes.MedicalEquipmentId == EquipmentId);

            if (supply != null)
            {
                supply.SupplyQuantity += Quantity;
                _context.MedicalEquipmentSupply.Update(supply);
            }
            else
            {
                supply = new MedicalEquipmentSupply(
                    _context.Hospital.First(h => h.Id == HospitalId),
                    _context.MedicalEquipment.First(e => e.Id == EquipmentId),
                    Quantity);

                _context.MedicalEquipmentSupply.Add(supply);
            }

            await _context.SaveChangesAsync();

            _recentlyOrdered.Add(EquipmentId);

            var ab = new { HospitalId = HospitalId };

            return(Json(ab));
        }
        public async Task <IActionResult> Edit(int id, [Bind("HospitalId,MedicalEquipmentId,SupplyQuantity")] MedicalEquipmentSupply medicalEquipmentSupply)
        {
            if (id != medicalEquipmentSupply.HospitalId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(medicalEquipmentSupply);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MedicalEquipmentSupplyExists(medicalEquipmentSupply.HospitalId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HospitalId"]         = new SelectList(_context.Hospital, "Id", "Id", medicalEquipmentSupply.HospitalId);
            ViewData["MedicalEquipmentId"] = new SelectList(_context.MedicalEquipment, "Id", "Name", medicalEquipmentSupply.MedicalEquipmentId);
            return(View(medicalEquipmentSupply));
        }
        public async Task <IActionResult> Create([Bind("HospitalId,MedicalEquipmentId,SupplyQuantity")] MedicalEquipmentSupply medicalEquipmentSupply)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicalEquipmentSupply);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HospitalId"]         = new SelectList(_context.Hospital, "Id", "Id", medicalEquipmentSupply.HospitalId);
            ViewData["MedicalEquipmentId"] = new SelectList(_context.MedicalEquipment, "Id", "Name", medicalEquipmentSupply.MedicalEquipmentId);
            return(View(medicalEquipmentSupply));
        }