Esempio n. 1
0
 public int GetMedicineId(Medicine medicine)
 {
     using (var dbContext = new ChronoDbContext())
     {
         return(dbContext.Medicines.FirstOrDefault(x => x.Name == medicine.Name).Id);
     }
 }
Esempio n. 2
0
 public List <Prescription> GetUserPrescriptions(int id)
 {
     using (var db = new ChronoDbContext())
     {
         return(db.Prescriptions.Where(x => x.UserId == id).ToList());
     }
 }
Esempio n. 3
0
 public int GetMedicineBoxId(int medicineId)
 {
     using (var dbContext = new ChronoDbContext())
     {
         return(dbContext.MedicineBoxes.FirstOrDefault(x => x.MedicineId == medicineId).Id);
     }
 }
Esempio n. 4
0
 public void SavePrescriptionToDb(Prescription prescription)
 {
     using (var dbContext = new ChronoDbContext())
     {
         dbContext.Prescriptions.Add(prescription);
         dbContext.SaveChanges();
     }
 }
Esempio n. 5
0
 public void SavePrescriptedMedToDb(PrescriptedMedicine prescriptedMedicine)
 {
     using (var dbContext = new ChronoDbContext())
     {
         dbContext.PrescriptedMedicines.Add(prescriptedMedicine);
         dbContext.SaveChanges();
     }
 }
Esempio n. 6
0
 public void SaveMedBoxToDb(MedicineBox medBox)
 {
     using (var dbContext = new ChronoDbContext())
     {
         dbContext.MedicineBoxes.Add(medBox);
         dbContext.SaveChanges();
     }
 }
Esempio n. 7
0
 public int GetPrescriptionId(Prescription prescription)
 {
     using (var dbContext = new ChronoDbContext())
     {
         return(dbContext.Prescriptions.FirstOrDefault(
                    x => x.Name == prescription.Name && x.DateOfIssue == prescription.DateOfIssue)
                .Id);
     }
 }
Esempio n. 8
0
        public static ChronoUser GetUserById(int userId)
        {
            ChronoUser user;

            using (var context = new ChronoDbContext())
            {
                user = context.Users.FirstOrDefault(x => x.Id == userId);
            }

            return(user);
        }
Esempio n. 9
0
        public Prescription GetPrescriptionById(int id)
        {
            Prescription prescription;

            using (var context = new ChronoDbContext())
            {
                prescription = context.Prescriptions.FirstOrDefault(x => x.Id == id);
            }

            prescription.PrescriptedMedicines = GetPrescriptedMedsList(id);

            return(prescription);
        }
Esempio n. 10
0
        public List <PrescriptedMedicine> GetPrescriptedMedsList(int id)
        {
            List <PrescriptedMedicine> prescriptedMedicines;

            using (var dbContext = new ChronoDbContext())
            {
                prescriptedMedicines = dbContext.PrescriptedMedicines
                                       .Join(dbContext.MedicineBoxes,
                                             prescriptedMed => prescriptedMed.MedicineBoxId,
                                             medBox => medBox.Id,
                                             (prescriptedMed, medBox) => new { prescriptedMed, medBox })
                                       .Join(dbContext.Medicines,
                                             medBox => medBox.medBox.MedicineId,
                                             med => med.Id,
                                             (medBox, med) => new { medBox, med })
                                       .Select(x => new
                {
                    Id                  = x.medBox.prescriptedMed.Id,
                    Name                = x.med.Name,
                    StartUsageDate      = x.medBox.prescriptedMed.StartUsageDate,
                    PrescriptedBoxCount = x.medBox.prescriptedMed.PrescriptedBoxCount,
                    Dose                = x.medBox.prescriptedMed.Dose,
                    PrescriptionId      = x.medBox.prescriptedMed.PrescriptionId,
                    MedicineBoxId       = x.medBox.medBox.Id
                })
                                       .AsEnumerable()
                                       .Select(x => new PrescriptedMedicine
                {
                    Id                  = x.Id,
                    Name                = x.Name,
                    StartUsageDate      = x.StartUsageDate,
                    PrescriptedBoxCount = x.PrescriptedBoxCount,
                    Dose                = x.Dose,
                    PrescriptionId      = x.PrescriptionId,
                    MedicineBoxId       = x.MedicineBoxId
                })
                                       .Where(x => x.PrescriptionId == id)
                                       .ToList();

                foreach (var element in prescriptedMedicines)
                {
                    element.Prescription = dbContext.Prescriptions.FirstOrDefault(x => x.Id == element.PrescriptionId);
                    element.MedicineBox  = dbContext.MedicineBoxes.FirstOrDefault(x => x.Id == element.MedicineBoxId);
                }
            }

            return(prescriptedMedicines);
        }
Esempio n. 11
0
 public ChronoRoleStore(ChronoDbContext context) : base(context)
 {
 }
Esempio n. 12
0
 public ChronoUserStore(ChronoDbContext context) : base(context)
 {
 }