Exemplo n.º 1
0
        public async Task <IActionResult> Edit(Int32?patientId, Int32?analysisId, AnalysesCreateEditViewModel model)
        {
            if (patientId == null || analysisId == null)
            {
                return(NotFound());
            }

            var analysis = await _context.Analyses.SingleOrDefaultAsync(m => m.PatientId == patientId && m.AnalysisId == analysisId);

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

            if (ModelState.IsValid)
            {
                analysis.Status = model.Status;
                analysis.Type   = model.Type;
                analysis.Date   = model.Date;
                analysis.LabId  = model.LabId;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { patientId = patientId }));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(Int32?patientId, AnalysesCreateEditViewModel model)
        {
            if (patientId == null)
            {
                return(this.NotFound());
            }
            var patient = await this._context.Patients
                          .SingleOrDefaultAsync(x => x.Id == patientId);

            if (patient == null)
            {
                return(this.NotFound());
            }


            if (ModelState.IsValid)
            {
                var analysisId = this._context.Analyses.Any() ? this._context.Analyses.Max(x => x.AnalysisId) + 1 : 1;
                var analysis   = new Analysis
                {
                    PatientId  = patient.Id,
                    AnalysisId = analysisId,
                    LabId      = model.LabId,
                    Date       = model.Date,
                    Status     = model.Status,
                    Type       = model.Type
                };
                _context.Add(analysis);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { patientId = patientId }));
            }

            this.ViewBag.Patient = patient;
            return(View(model));
        }