public JsonResult EditMedicalReport(MedicalReportViewModel model) { var result = new { Success = "true", Message = "Success" }; if (ModelState.IsValid) { if (model.CompletionDate >= model.NextCompletionDate) { result = new { Success = "false", Message = "Data ważności badania nie może być wcześniejsza niż data wykonania badania." }; return(Json(result, JsonRequestBehavior.AllowGet)); } var employee = _employeeService.GetById(model.EmployeeId); var lastCheck = employee.MedicalReports?.Where(x => !x.IsDeleted).OrderByDescending(x => x.Id).FirstOrDefault(); if ((lastCheck != null && lastCheck.NextCompletionDate > model.NextCompletionDate)) { result = new { Success = "false", Message = "Data ważności nowego badania musi być późniejsza od daty ważności poprzedniego." }; return(Json(result, JsonRequestBehavior.AllowGet)); } try { var mReport = Mapper.Map <MedicalReport>(model); mReport.UpdatedDate = DateTime.Now; _medicalReportService.Update(mReport); } catch (Exception e) { logger.Error(e, e.Message); result = new { Success = "false", Message = WebResources.ErrorMessage }; } return(Json(result, JsonRequestBehavior.AllowGet)); } else { var error = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage; result = new { Success = "false", Message = error }; return(Json(result, JsonRequestBehavior.AllowGet)); } }
public ActionResult SendEmailMedicalReportsExpiredReminderNotifications() { int daysBeforeExpiration = SettingsHandler.DaysBeforeIntervalReminder; var medicalReportsToExpire = _medicalReportService.GetMedicalReportsToExpire(daysBeforeExpiration); foreach (var medicalReport in medicalReportsToExpire) { try { var message = CreateMedicalReportReminderMessage(medicalReport); var result = _emailMessageService.SendEmailMessage(message); medicalReport.ReminderSent = true; _medicalReportService.Update(medicalReport); } catch (Exception e) { logger.Error(e, e.Message); } } return(null); }