Beispiel #1
0
        public ActionResult EditContact(int id)
        {
            var viewModel = new DoctorContactViewModel();

            InitViewBag();

            if (id == 0)
            {
                viewModel.Attitude       = Attitude.Unknown;
                viewModel.Status         = Status.NewlyIdentified;
                viewModel.OriginalStatus = Status.NewlyIdentified;
            }
            else
            {
                // Retrieve existing data and populate model
                var doctor = _doctorRepository.Get(id);
                if (doctor == null)
                {
                    return(RedirectToAction("Search", "Home",
                                            new { msg = $"DoctorId {id} was not found in the database." }));
                }

                viewModel = Mapper.Map <DoctorContactViewModel>(doctor);
                viewModel.OriginalStatus = doctor.Status;
                viewModel.EmailAddress   = viewModel.EmailAddress?.Trim();
            }
            return(View(viewModel));
        }
Beispiel #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 }));
        }
 internal bool SaveContact(DoctorContactViewModel model)
 {
     try
     {
         if (model.Id == 0)
         {
             Connection.Insert(model);
         }
         else
         {
             Connection.Update(model);
         }
         // Force refresh of Doctors in cache
         GetSelectList(true);
         GetSelectListAnesthesiologists(true);
         return(true);
     }
     catch (Exception ex)
     {
         LogException(ex, model);
         return(false);
     }
 }