//----GET voor Delete ---------------------------------------------------- public IActionResult Delete(int prescrId) { var prescr = _prescrManager.GetPrescr(prescrId); var pLineList = _prescrManager.GetPrescrLines(prescrId); var pW5LinesVM = new PrescrWith5LinesViewModel { ClientFullName = _clientManager.ClientFullName(prescr.ClientId), DoctorFullName = _clientManager.DoctorFullName(prescr.DoctorId), Prescription = prescr }; if (pLineList.ElementAtOrDefault(0) != null) { pW5LinesVM.Line1 = pLineList.ElementAt(0).Line; } if (pLineList.ElementAtOrDefault(1) != null) { pW5LinesVM.Line2 = pLineList.ElementAt(1).Line; } if (pLineList.ElementAtOrDefault(2) != null) { pW5LinesVM.Line3 = pLineList.ElementAt(2).Line; } if (pLineList.ElementAtOrDefault(3) != null) { pW5LinesVM.Line4 = pLineList.ElementAt(3).Line; } if (pLineList.ElementAtOrDefault(4) != null) { pW5LinesVM.Line5 = pLineList.ElementAt(4).Line; } return(View(pW5LinesVM)); }
public IActionResult Update(PrescrWith5LinesViewModel pW5LinesVM) { // Check eerst de standaard fouten: if (!ModelState.IsValid) { return(View(pW5LinesVM)); } // Check hier de velden op complexere correcte invoer // Stop met valideren bij de eerste gevonden fout string errMsg = ErrorCheck.CheckForErrors(pW5LinesVM); if (errMsg != null) // Specifieke fout gevonden { ModelState.AddModelError(string.Empty, errMsg); return(View(pW5LinesVM)); } // converteer pW5LinesVM naar PrescrWithLine via extension method var prescr = pW5LinesVM.ToPrescr(); var prescrLineList = pW5LinesVM.ToPrescrLineList(); _prescrManager.UpdPrescrAndLines(prescr, prescrLineList); return(RedirectToAction("Index", new { doctorId = pW5LinesVM.Prescription.DoctorId, clientId = pW5LinesVM.Prescription.ClientId })); }
// ----------------------------------------------------------------------- internal static string CheckForErrors(PrescrWith5LinesViewModel pW5LinesVM) { bool fmtOK; fmtOK = CheckFmt(pW5LinesVM.Prescription.PrescriptionDescr, patternGeneral); if (!fmtOK) { return("Formaat van \'Omschrijving recept\' is incorrect"); } if (pW5LinesVM.Line1 != null) { fmtOK = CheckFmt(pW5LinesVM.Line1, patternGeneral); if (!fmtOK) { return("Formaat van \'Recept regel 1\' is incorrect"); } } if (pW5LinesVM.Line2 != null) { fmtOK = CheckFmt(pW5LinesVM.Line2, patternGeneral); if (!fmtOK) { return("Formaat van \'Recept regel 2\' is incorrect"); } } if (pW5LinesVM.Line3 != null) { fmtOK = CheckFmt(pW5LinesVM.Line3, patternGeneral); if (!fmtOK) { return("Formaat van \'Recept regel 3\' is incorrect"); } } if (pW5LinesVM.Line4 != null) { fmtOK = CheckFmt(pW5LinesVM.Line4, patternGeneral); if (!fmtOK) { return("Formaat van \'Recept regel 4\' is incorrect"); } } if (pW5LinesVM.Line5 != null) { fmtOK = CheckFmt(pW5LinesVM.Line5, patternGeneral); if (!fmtOK) { return("Formaat van \'Recept regel 5\' is incorrect"); } } return(null); }
internal static List <PrescriptionLine> ToPrescrLineList(this PrescrWith5LinesViewModel pW5LinesVM) { var prescrLineList = new List <PrescriptionLine>(); if (pW5LinesVM.Line1 != null) { prescrLineList.Add(new PrescriptionLine { PrescriptionId = pW5LinesVM.Prescription.Id, Line = pW5LinesVM.Line1 }); } if (pW5LinesVM.Line2 != null) { prescrLineList.Add(new PrescriptionLine { PrescriptionId = pW5LinesVM.Prescription.Id, // ?????? Line = pW5LinesVM.Line2 }); } if (pW5LinesVM.Line3 != null) { prescrLineList.Add(new PrescriptionLine { PrescriptionId = pW5LinesVM.Prescription.Id, // ?????? Line = pW5LinesVM.Line3 }); } if (pW5LinesVM.Line4 != null) { prescrLineList.Add(new PrescriptionLine { PrescriptionId = pW5LinesVM.Prescription.Id, // ?????? Line = pW5LinesVM.Line4 }); } if (pW5LinesVM.Line5 != null) { prescrLineList.Add(new PrescriptionLine { PrescriptionId = pW5LinesVM.Prescription.Id, // ?????? Line = pW5LinesVM.Line5 }); } return(prescrLineList); }
//------------------------------------------------------------------- internal static Prescription ToPrescr(this PrescrWith5LinesViewModel pW5LinesVM) { // Map only fields 1:1 from ViewModel to Model var result = new Prescription { Id = pW5LinesVM.Prescription.Id, ActionCode = pW5LinesVM.Prescription.ActionCode, ClientId = pW5LinesVM.Prescription.ClientId, DoctorId = pW5LinesVM.Prescription.DoctorId, PrescriptionDate = pW5LinesVM.Prescription.PrescriptionDate, PrescriptionDescr = pW5LinesVM.Prescription.PrescriptionDescr, Price = pW5LinesVM.Prescription.Price, CommentForDoctor = pW5LinesVM.Prescription.CommentForDoctor }; return(result); }
// ---------------- Create-GET ------------------------------ public IActionResult Create(int doctorId, int clientId) // Een recept kan alleen worden gecreƫerd als zowel de arts // als de client bekend is. { var pW5LinesVM = new PrescrWith5LinesViewModel(); pW5LinesVM.ClientFullName = _clientManager.ClientFullName(clientId); pW5LinesVM.DoctorFullName = _clientManager.DoctorFullName(doctorId); // Vergeet onderstaande regel niet, // Immers de Create View moet 2 hidden fields krijgen voor clientId en doctorId // Zo niet, dan zijn deze 2 sleutelwaarden verloren bij inkomende VM voor de POST CREATE pW5LinesVM.Prescription = new Prescription { ClientId = clientId, DoctorId = doctorId }; pW5LinesVM.Prescription.PrescriptionDate = DateTime.Now; return(View(pW5LinesVM)); }
// Update - Get ------------------------------------ public IActionResult Update(int prescrId) { var prescr = _prescrManager.GetPrescr(prescrId); var pLineList = _prescrManager.GetPrescrLines(prescrId); // Maak viewmodel voor 1 Prescription, inclusief // FullName van client en dokter en inclusief // max 5 lijnen // Preconditie: in de database komen geen lijnen voor // met waarde NULL // Algemene velden: var pW5LinesVM = new PrescrWith5LinesViewModel { ClientFullName = _clientManager.ClientFullName(prescr.ClientId), DoctorFullName = _clientManager.DoctorFullName(prescr.DoctorId), Prescription = prescr }; if (pLineList.ElementAtOrDefault(0) != null) { pW5LinesVM.Line1 = pLineList.ElementAt(0).Line; } if (pLineList.ElementAtOrDefault(1) != null) { pW5LinesVM.Line2 = pLineList.ElementAt(1).Line; } if (pLineList.ElementAtOrDefault(2) != null) { pW5LinesVM.Line3 = pLineList.ElementAt(2).Line; } if (pLineList.ElementAtOrDefault(3) != null) { pW5LinesVM.Line4 = pLineList.ElementAt(3).Line; } if (pLineList.ElementAtOrDefault(4) != null) { pW5LinesVM.Line5 = pLineList.ElementAt(4).Line; } return(View(pW5LinesVM)); }
public IActionResult Create(PrescrWith5LinesViewModel pW5LinesVM) { // Onderstaande werkt niet: if (!ModelState.IsValid) { pW5LinesVM.Prescription.PrescriptionDescr = "Descr is CHANGED"; return(View(pW5LinesVM)); } // Check hier de velden op correcte invoer (complexer) // Stop met valideren bij de eerste gevonden fout // Opmerking: als je spaties invult in een Line, wordt dit // als een NULL string terug aan deze POST ACTION Method teruggegeven string errMsg = ErrorCheck.CheckForErrors(pW5LinesVM); if (errMsg != null) // Specifieke fout gevonden { ModelState.AddModelError(string.Empty, errMsg); // VM moet altijd in de return, ook al doet het scherm er niets mee // Het scherm verwacht altijd deze VM, zowel bij de Get als bij de Create return(View(pW5LinesVM)); } var prescr = pW5LinesVM.ToPrescr(); var prescrLineList = pW5LinesVM.ToPrescrLineList(); _prescrManager.AddPrescrAndLines(prescr, prescrLineList); return(RedirectToAction("Index", new { doctorId = pW5LinesVM.Prescription.DoctorId, clientId = pW5LinesVM.Prescription.ClientId })); }