Ejemplo n.º 1
0
        private List <TakenMedicine> GetMyTodayMedicines()
        {
            string               userId           = User.Identity.GetUserId();
            List <string>        myMedecineIds    = db.PatientMedicine.Where(pm => pm.Patient_AspNetUsers_Id == userId).Select(pm => pm.Id).ToList();
            List <TakenMedicine> myTodayMedicines = new List <TakenMedicine>();

            foreach (string medicineId in myMedecineIds)
            {
                try
                {
                    TakenMedicine takenMedicine = db.TakenMedicine.Where(tm => tm.PatientMedicine_Id == medicineId).Single(tm => tm.Day == DateTime.Today);
                    takenMedicine.PatientMedicine = db.PatientMedicine.Single(pm => pm.Id == medicineId);
                    myTodayMedicines.Add(takenMedicine);
                }
                catch (InvalidOperationException)
                {
                    TakenMedicine takenMedicine = new TakenMedicine()
                    {
                        Day = DateTime.Today,
                        PatientMedicine_Id = medicineId,
                        Taken           = false,
                        PatientMedicine = db.PatientMedicine.Single(pm => pm.Id == medicineId),
                    };
                    myTodayMedicines.Add(takenMedicine);
                    db.TakenMedicine.Add(takenMedicine);
                    db.SaveChanges();
                }
            }
            return(myTodayMedicines);
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(string id)
        {
            TakenMedicine takenMedicine = db.TakenMedicine.Find(id);

            db.TakenMedicine.Remove(takenMedicine);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Day,PatientMedicine_Id,Taken")] TakenMedicine takenMedicine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(takenMedicine).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(takenMedicine));
 }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Diary_Id,PatientMedicine_Id,Taken")] TakenMedicine takenMedicine)
        {
            if (ModelState.IsValid)
            {
                db.TakenMedicine.Add(takenMedicine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(takenMedicine));
        }
Ejemplo n.º 5
0
        // GET: TakenMedicines/Edit/5
        public ActionResult Edit(string patientMedicineID, DateTime dayId)
        {
            if (patientMedicineID == null || dayId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TakenMedicine takenMedicine = db.TakenMedicine.Find(patientMedicineID, dayId);

            if (takenMedicine == null)
            {
                return(HttpNotFound());
            }
            return(View(takenMedicine));
        }
Ejemplo n.º 6
0
        // GET: TakenMedicines/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TakenMedicine takenMedicine = db.TakenMedicine.Find(id);

            if (takenMedicine == null)
            {
                return(HttpNotFound());
            }
            return(View(takenMedicine));
        }
Ejemplo n.º 7
0
 // GET: TakenMedicines/Take
 public ActionResult Take(string patientMedicineID, DateTime day)
 {
     if (patientMedicineID != null && day != null)
     {
         TakenMedicine takenMedicine = db.TakenMedicine.Find(patientMedicineID, day);
         if (takenMedicine != null)
         {
             takenMedicine.Taken           = !takenMedicine.Taken;
             db.Entry(takenMedicine).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }