コード例 #1
0
        public async Task <IActionResult> PostPrescription([FromBody] Prescription prescription)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _prescriptionRepository.CreateAsync(prescription);

            foreach (var medicinePrescription in prescription.MedicinePrescriptions)
            {
                Medicine medicine = await _medicineRepository.FindAsync(medicinePrescription.MedicineId);

                if (medicinePrescription.Quantity <= medicine.Stock)
                {
                    medicine.Stock -= medicinePrescription.Quantity;
                    _medicineRepository.Update(medicine);
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }

            await _prescriptionRepository.SaveChangesAsync();

            return(CreatedAtAction("GetPrescription", new { id = prescription.Id }, prescription));
        }
コード例 #2
0
        public async Task <IActionResult> PostStockOrder([FromBody] StockOrder stockOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _stockOrderRepository.CreateAsync(stockOrder);

            foreach (var medicineStockOrder in stockOrder.MedicineStockOrders)
            {
                Medicine medicine = await _medicineRepository.FindAsync(medicineStockOrder.MedicineId);

                if (medicineStockOrder.Quantity < 0)
                {
                    medicine.Stock -= (uint)Math.Abs(medicineStockOrder.Quantity);
                }
                else
                {
                    medicine.Stock += (uint)medicineStockOrder.Quantity;
                }
                _medicineRepository.Update(medicine);
            }

            await _stockOrderRepository.SaveChangesAsync();

            return(CreatedAtAction("GetStockOrder", new { id = stockOrder.Id }, stockOrder));
        }
コード例 #3
0
        public async Task <IActionResult> GetMedicine([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var medicine = await _medicineRepository.FindAsync(id);

            if (medicine == null)
            {
                return(NotFound());
            }

            return(Ok(medicine));
        }
コード例 #4
0
        public async Task <IActionResult> PostPurchaseOrder([FromBody] PurchaseOrder purchaseOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _purchaseOrderRepository.CreateAsync(purchaseOrder);

            foreach (var medicinePurchaseOrder in purchaseOrder.MedicinePurchaseOrders)
            {
                Medicine medicine = await _medicineRepository.FindAsync(medicinePurchaseOrder.MedicineId);

                medicine.Stock += medicinePurchaseOrder.Quantity;
                _medicineRepository.Update(medicine);
            }

            await _purchaseOrderRepository.SaveChangesAsync();

            return(CreatedAtAction("GetPurchaseOrders", new { id = purchaseOrder.Id }, purchaseOrder));
        }