public ActionResult AddVaccine(ViewModel vm) { DataLayer dal = new DataLayer(); string pId = Request.Form["patientId"], mId = User.Identity.Name; List <ImmuneCard> cards = (from x in dal.ImmuneCards select x).ToList <ImmuneCard>(); ImmuneCard card = null; foreach (ImmuneCard c in cards) { if (AES.Decrypt(c.patientId) == pId) { card = c; } } List <Medic> medics = (from x in dal.medics select x).ToList <Medic>(); Medic medic = null; foreach (Medic m in medics) { if (AES.Decrypt(m.Id) == User.Identity.Name) { medic = m; } } vm.patients = (from x in dal.patients select x).ToList <Patient>(); foreach (Patient p in vm.patients) { if (AES.Decrypt(p.Id) == pId) { vm.patient = p; } } if (ModelState.IsValid) { vm.vaccine = AES.EncryptVaccine(vm.vaccine); vm.patient.card.Vaccines.Add(vm.vaccine); vm.vaccine.card = vm.patient.card; vm.vaccine.medic = medic; ViewBag.message = "Vaccine added succesfully."; dal.SaveChanges(); vm.patient = AES.DecryptPatient(vm.patient); return(View("PatientPage", vm.patient)); } else { ViewBag.message = "Invalid vaccine information."; return(View("AddVaccine", vm)); } }
public static ImmuneCard DecryptCard(ImmuneCard card) { card.patientId = Decrypt(card.patientId); card.Vaccines = DecryptVaccineList(card.Vaccines); return(card); }
public static ImmuneCard EncryptCard(ImmuneCard card) { card.patientId = Encrypt(card.patientId); return(card); }