public ActionResult Edit(PracticeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.Practice.State = model.Practice.State?.ToUpper();

            _practiceRepository.Save(model);

            return(RedirectToAction("View", new { id = model.Practice.Id }));
        }
Exemple #2
0
        public ActionResult EditContact(DoctorContactViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                InitViewBag();
                return(View(viewModel));
            }

            //var returnMsg = "There was an error updating this Doctor's information.";

            if (viewModel.Status != viewModel.OriginalStatus || viewModel.StatusDate == DateTime.MinValue)
            {
                viewModel.StatusDate = DateTime.Now;
            }

            if (viewModel.Id == 0)
            {
                viewModel.DateEntered     = DateTime.Now;
                viewModel.EnteredBy       = Session["UserId"].ToString();
                viewModel.DateLastUpdated = viewModel.DateEntered;
                viewModel.LastUpdatedBy   = viewModel.EnteredBy;
            }
            else
            {
                viewModel.DateLastUpdated = DateTime.Now;
                viewModel.LastUpdatedBy   = Session["UserId"].ToString();
            }

            // See if user added a new Practice on the fly
            if (viewModel.PracticeId == -1 && !string.IsNullOrEmpty(viewModel.Practice.PracticeName))
            {
                var practice = new PracticeViewModel()
                {
                    Practice = viewModel.Practice
                };
                practice.Practice.Id = 0;  // signal we are Inserting

                _practiceRepository.Save(practice);
                viewModel.PracticeId = practice.Practice.Id;
            }

            _doctorRepository.SaveContact(viewModel);

            //if (_doctorRepository.Save(model))
            //    returnMsg = $"Contact information for {model.FirstName + " " + model.LastName} was edited successfully.";

            return(RedirectToAction("View", new { id = viewModel.Id }));
        }