public async Task <IActionResult> PutMedicalPrescription(long id, MedicalPrescription medicalPrescription)
        {
            if (id != medicalPrescription.Id)
            {
                return(BadRequest());
            }

            var drug = await _context.Drugs.SingleOrDefaultAsync(drug => drug.Id == medicalPrescription.DrugId);

            medicalPrescription.TotalPrice = medicalPrescription.Quantity * drug.Price;

            _context.Entry(medicalPrescription).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MedicalPrescriptionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public void SetUp()
        {
            MapperDependencyResolver.Resolve();
            context = new DrugstoreDbContext(options);
            #region Data seed
            var stockMed = new MedicineOnStock
            {
                MedicineCategory = MedicineCategory.Special,
                PricePerOne      = 30,
                Quantity         = 50,
                Refundation      = 0.20,
                Name             = "Lek testowy"
            };
            var doctor = new Doctor
            {
                FirstName  = "Testowy",
                SecondName = "Lekarz"
            };
            var patient = new Patient
            {
                FirstName  = "Testowy",
                SecondName = "Pacjent"
            };
            var prescription = new MedicalPrescription
            {
                CreationTime      = DateTime.Now,
                Doctor            = doctor,
                Patient           = patient,
                VerificationState = VerificationState.NotVerified,
                Medicines         = new List <AssignedMedicine> {
                    new AssignedMedicine {
                        StockMedicine    = stockMed,
                        PricePerOne      = stockMed.PricePerOne * (1 - stockMed.Refundation),
                        AssignedQuantity = 10
                    }
                }
            };

            context.Doctors.Add(doctor);

            context.Patients.Add(patient);

            context.Medicines.Add(stockMed);

            context.MedicalPrescriptions.Add(prescription);
            context.SaveChanges();
            #endregion
        }
        private MedicalPrescriptionDTO GetMedicalPrescriptionInfo(MedicalPrescription medicalPrescription)
        {
            var doctor  = _context.Users.SingleOrDefault(doctor => doctor.Id == medicalPrescription.DoctorId);
            var patient = _context.Users.SingleOrDefault(patient => patient.Id == medicalPrescription.PatientId);
            var drug    = _context.Drugs.SingleOrDefault(drug => drug.Id == medicalPrescription.DrugId);

            MedicalPrescriptionDTO medicalPrescriptionDTO = new MedicalPrescriptionDTO();

            medicalPrescriptionDTO.Id         = medicalPrescription.Id;
            medicalPrescriptionDTO.Doctor     = doctor;
            medicalPrescriptionDTO.Patient    = patient;
            medicalPrescriptionDTO.Drug       = drug;
            medicalPrescriptionDTO.Quantity   = medicalPrescription.Quantity;
            medicalPrescriptionDTO.TotalPrice = medicalPrescription.TotalPrice;

            return(medicalPrescriptionDTO);
        }
Esempio n. 4
0
        public void SetUp()
        {
            MapperDependencyResolver.Resolve();
            context = new DrugstoreDbContext(options);
            #region Data seed
            var stockMedOne = new MedicineOnStock
            {
                MedicineCategory = MedicineCategory.Special,
                PricePerOne      = 30,
                Quantity         = 50,
                Refundation      = 0.20,
                Name             = "Lek testowy"
            };
            var stockMedTwo = new MedicineOnStock
            {
                MedicineCategory = MedicineCategory.Normal,
                PricePerOne      = 20,
                Quantity         = 100,
                Refundation      = 0.60,
                Name             = "Voltaren"
            };

            var doctor = new Doctor
            {
                FirstName  = "Testowy",
                SecondName = "Lekarz"
            };

            var patientOne = new Patient
            {
                FirstName  = "Pacjentka",
                SecondName = "One"
            };

            var patientTwo = new Patient
            {
                FirstName  = "Pacjent",
                SecondName = "Two"
            };
            var prescriptions = new MedicalPrescription []
            {
                new MedicalPrescription {
                    CreationTime      = DateTime.Parse("2019/01/20"),
                    Doctor            = doctor,
                    Patient           = patientOne,
                    VerificationState = VerificationState.NotVerified,
                    Medicines         = new List <AssignedMedicine> {
                        new AssignedMedicine {
                            StockMedicine    = stockMedOne,
                            PricePerOne      = stockMedOne.PricePerOne * (1 - stockMedOne.Refundation),
                            AssignedQuantity = 10
                        }
                    }
                },
                new MedicalPrescription
                {
                    CreationTime      = DateTime.Parse("2019/01/22"),
                    Doctor            = doctor,
                    Patient           = patientOne,
                    VerificationState = VerificationState.NotVerified,
                    Medicines         = new List <AssignedMedicine> {
                        new AssignedMedicine {
                            StockMedicine    = stockMedTwo,
                            PricePerOne      = stockMedTwo.PricePerOne * (1 - stockMedTwo.Refundation),
                            AssignedQuantity = 10
                        }
                    }
                },

                new MedicalPrescription
                {
                    CreationTime      = DateTime.Parse("2019/01/28"),
                    Doctor            = doctor,
                    Patient           = patientTwo,
                    VerificationState = VerificationState.Accepted,
                    Medicines         = new List <AssignedMedicine> {
                        new AssignedMedicine {
                            StockMedicine    = stockMedOne,
                            PricePerOne      = stockMedOne.PricePerOne * (1 - stockMedOne.Refundation),
                            AssignedQuantity = 10
                        }
                    }
                },
                new MedicalPrescription
                {
                    CreationTime      = DateTime.Parse("2019/01/30"),
                    Doctor            = doctor,
                    Patient           = patientTwo,
                    VerificationState = VerificationState.Accepted,
                    Medicines         = new List <AssignedMedicine> {
                        new AssignedMedicine {
                            StockMedicine    = stockMedTwo,
                            PricePerOne      = stockMedTwo.PricePerOne * (1 - stockMedTwo.Refundation),
                            AssignedQuantity = 10
                        }
                    }
                }
            };

            context.Doctors.Add(doctor);

            context.Patients.Add(patientTwo);

            context.Medicines.Add(stockMedOne);
            context.Medicines.Add(stockMedTwo);

            context.MedicalPrescriptions.AddRange(prescriptions);

            context.SaveChanges();
            #endregion
        }
        public async Task <ActionResult <MedicalPrescription> > PostMedicalPrescription(MedicalPrescription medicalPrescription)
        {
            var drug = await _context.Drugs.SingleOrDefaultAsync(drug => drug.Id == medicalPrescription.DrugId);

            medicalPrescription.TotalPrice = medicalPrescription.Quantity * drug.Price;

            _context.MedicalPrescriptions.Add(medicalPrescription);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetMedicalPrescription), new { id = medicalPrescription.Id }, GetMedicalPrescriptionInfo(medicalPrescription)));
        }