// GET: Admin/Medical/ViewPrescription public ActionResult ViewPrescription(string id = "") { try { int _id; MedicalPrescriptionInfo _prescription = null; if (!int.TryParse(id, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(View(_prescription)); } using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { _prescription = Repo.GetMedicalPrescriptionById(_id); if (_prescription == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription not found."); return(View(_prescription)); } } return(View(_prescription)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "ViewPrescription"))); } }
public ActionResult DownloadPrescription(string id = "") { try { int _id; MedicalPrescriptionInfo _prescription = null; if (!int.TryParse(id, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Requests", "Medical")); } using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { _prescription = Repo.GetMedicalPrescriptionById(_id); if (_prescription == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription not found."); return(RedirectToAction("Requests", "Medical")); } } var prescriptionPath = Server.MapPath(_prescription.PrescriptionPath); return(File(prescriptionPath, MimeMapping.GetMimeMapping(prescriptionPath), _prescription.FileName)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "DownloadPrescription"))); } }
public void SaveMedicalPrescription(MedicalPrescriptionInfo medicalPrescriptionInfo) { Data.MedicalPrescription medicalPrescription = ConvertToDb(medicalPrescriptionInfo); _context.MedicalPrescriptions.Add(medicalPrescription); _context.SaveChanges(); }
public Data.MedicalPrescription ConvertToDb(MedicalPrescriptionInfo medicalPrescriptionInfo) { return(new Data.MedicalPrescription { Id = medicalPrescriptionInfo.Id, PrescriptionPath = medicalPrescriptionInfo.PrescriptionPath, FileName = medicalPrescriptionInfo.FileName, UploadDate = medicalPrescriptionInfo.UploadDate, MedicalCheckoutId = medicalPrescriptionInfo.MedicalCheckoutId }); }
public ActionResult DeletePrescription(string PrescriptionId) { try { int id; MedicalPrescriptionInfo _prescription = null; if (!int.TryParse(PrescriptionId, out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Medical")); } using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { _prescription = Repo.GetMedicalPrescriptionById(id); if (_prescription == null || _prescription.EmployeeInfoId != CurrentUser.EmployeeInfoId || _prescription.CheckoutStatus == "Approved") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription not found."); return(RedirectToAction("Details", "Medical")); } string _prescriptionPath = Request.MapPath(_prescription.PrescriptionPath); if (System.IO.File.Exists(_prescriptionPath)) { System.IO.File.Delete(_prescriptionPath); Repo.DeleteMedicalPrescription(_prescription.Id); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription does not exist physically."); } } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Prescription deleted successfully."); return(RedirectToAction("Apply", "Medical", new { id = _prescription.MedicalCheckoutId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "DeletePrescription"))); } }
public void UpdateMedicalPrescription(MedicalPrescriptionInfo medicalPrescriptionInfo) { Data.MedicalPrescription medicalPrescription = _context.MedicalPrescriptions.Find(medicalPrescriptionInfo.Id); if (medicalPrescription != null) { //Not implemented yet //medicalAllowance.Category = medicalAllowanceInfo.Category; //medicalAllowance.Amount = medicalAllowanceInfo.Amount; _context.SaveChanges(); } else { throw new ArgumentNullException(); } }
public ActionResult UploadPrescription(HttpPostedFileBase file, MedicalCheckoutInfo medicalCheckoutInfo) { try { int id; MedicalCheckoutInfo _medicalCheckout = null; var _prescription = new MedicalPrescriptionInfo(); if (!int.TryParse(medicalCheckoutInfo.Id.ToString(), out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong please try again later."); return(RedirectToAction("Details", "Medical")); } using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository()) { _medicalCheckout = Repo.GetMedicalCheckoutById(id); } if (_medicalCheckout == null || _medicalCheckout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _medicalCheckout.Status == "Approved") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found."); return(RedirectToAction("Details", "Medical")); } if (string.IsNullOrEmpty(medicalCheckoutInfo.PrescriptionName)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription name is required."); return(RedirectToAction("Details", "Medical")); } if (file != null) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg")) { _prescription.FileName = medicalCheckoutInfo.PrescriptionName + Path.GetExtension(file.FileName); _prescription.UploadDate = DateTime.Now; _prescription.MedicalCheckoutId = medicalCheckoutInfo.Id; string _dirPath = Server.MapPath(Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions")); bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath); if (!_isDirectoryExists) { System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions"))); } Guid guid = Guid.NewGuid(); _prescription.PrescriptionPath = Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions/" + _medicalCheckout.EmployeeInfoId + "-" + guid + "-" + _prescription.FileName); string _prescriptionPath = Server.MapPath(_prescription.PrescriptionPath); using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { file.SaveAs(_prescriptionPath); Repo.SaveMedicalPrescription(_prescription); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select 'jpeg, jpg' format only."); return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select prescription."); return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id })); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Prescription uploaded successfully."); return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "UploadPrescription"))); } }