public async Task DischargeUser(ApplicationUser user, InfectionDischarge report)
        {
            var infectionReport = await _context.InfectionReport.FindAsync(report.InfectionReportId);

            if (infectionReport == null)
            {
                throw new ModelException("Previous infection report not found");
            }

            if (infectionReport.DiagnosisDate >= report.DischargedDate)
            {
                throw new ModelException("Discharge date should be subsequent to the Diagnosis date",
                                         (ModelState => { ModelState.AddModelError("DischargedDate", "La fecha de alta debe ser posterior a la de diagnostico"); })
                                         );
            }
            if (report.DischargedDate > Time.Now())
            {
                throw new ModelException("Discharge date can't be more recent than present date",
                                         (ModelState => { ModelState.AddModelError("DischargedDate", "La fecha de dada de alta no puede ser posterior a la fecha actual."); })
                                         );
            }

            infectionReport.DischargedDate = report.DischargedDate;

            _context.Update(infectionReport);
            await _context.SaveChangesAsync();

            await _userInfoManager.UpdateStatus(user, InfectionStatus.Healthy, null);
        }
        public async Task <IActionResult> Discharge()
        {
            var currentUser = await _userInfoManager.FindUser(User);

            if (!currentUser.Infected)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var infectionReport = await _userInfoManager.GetOpenInfectionReport(currentUser);

            if (infectionReport == null)
            {
                return(NotFound());
            }

            var infectionDischarge = new InfectionDischarge
            {
                InfectionReportId = infectionReport.Id,
                DiagnosisDate     = infectionReport.DiagnosisDate,
                DischargedDate    = Time.Now()
            };


            return(View(infectionDischarge));
        }
        public async Task <IActionResult> Discharge(InfectionDischarge infectionDischarge)
        {
            var currentUser = await _userInfoManager.FindUser(User);

            try { await _infectionManager.DischargeUser(currentUser, infectionDischarge); }
            catch (ModelException ex)
            {
                ex.UpdateModelState(ModelState);
                return(View(infectionDischarge));
            }

            return(RedirectToAction("Index", "Home"));
        }