public ActionResult Create(DiagnosticHypothesisViewModel[] diagnosticHypotheses)
 {
     return this.Edit(diagnosticHypotheses);
 }
        public ActionResult Edit(int? id, int? patientId, int? y, int? m, int? d)
        {
            DiagnosticHypothesisViewModel viewModel = null;

            if (id != null)
                viewModel = GetViewModel(
                    (from a in this.db.DiagnosticHypotheses where a.Id == id select a).First(),
                    this.GetToLocalDateTimeConverter());
            else
                viewModel = new DiagnosticHypothesisViewModel()
                {
                    Id = null,
                    PatientId = patientId,
                    MedicalRecordDate = DateTimeHelper.CreateDate(y, m, d) ?? this.GetPracticeLocalNow(),
                };

            return this.View("Edit", viewModel);
        }
        public ActionResult Edit(DiagnosticHypothesisViewModel[] diagnosticHypotheses)
        {
            var formModel = diagnosticHypotheses.Single();

            Debug.Assert(formModel.PatientId != null, "formModel.PatientId != null");
            if (this.ModelState.IsValid)
            {
                DiagnosticHypothesis diagnosticHypothesis;
                if (formModel.Id == null)
                {
                    diagnosticHypothesis = new DiagnosticHypothesis
                    {
                        CreatedOn = this.GetUtcNow(),
                        PatientId = formModel.PatientId.Value,
                        PracticeId = this.DbUser.PracticeId
                    };
                    this.db.DiagnosticHypotheses.AddObject(diagnosticHypothesis);
                }
                else
                    diagnosticHypothesis = this.db.DiagnosticHypotheses.First(a => a.Id == formModel.Id);

                diagnosticHypothesis.Patient.IsBackedUp = false;
                diagnosticHypothesis.Observations = formModel.Text;
                diagnosticHypothesis.Cid10Code = formModel.Cid10Code;
                diagnosticHypothesis.Cid10Name = formModel.Cid10Name;
                diagnosticHypothesis.MedicalRecordDate = this.ConvertToUtcDateTime(formModel.MedicalRecordDate.Value);

                this.db.SaveChanges();

                // todo: this shoud be a redirect... so that if user press F5 in browser, the object will no be saved again.
                return this.View("Details", GetViewModel(diagnosticHypothesis, this.GetToLocalDateTimeConverter()));
            }

            return this.View("Edit", formModel);
        }