Exemplo n.º 1
0
        public virtual IActionResult Edit(DoctorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDoctors))
            {
                return(AccessDeniedView());
            }

            //try to get a doctor with the specified id
            var doctor = _doctorService.GetDoctorById(model.Id);

            if (doctor == null)
            {
                return(RedirectToAction("List"));
            }

            var doctorsError = ValidateDoctors(model);

            if (!string.IsNullOrEmpty(doctorsError))
            {
                ModelState.AddModelError(string.Empty, doctorsError);
                ErrorNotification(doctorsError, false);
            }

            try
            {
                if (ModelState.IsValid)
                {
                    doctor = model.ToEntity(doctor);
                    _doctorService.UpdateDoctor(doctor);

                    //activity log
                    _customerActivityService.InsertActivity("EditDoctor",
                                                            string.Format(_localizationService.GetResource("ActivityLog.EditDoctor"), doctor.FullName), doctor);

                    SuccessNotification(_localizationService.GetResource("Hero.Admin.Doctors.Updated"));

                    return(continueEditing ? RedirectToAction("Edit", new { id = doctor.Id }) : RedirectToAction("List"));
                }

                //prepare model
                model = _doctorModelFactory.PrepareDoctorModel(model, doctor, true);

                //if we got this far, something failed, redisplay form
                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("Edit", new { id = doctor.Id }));
            }
        }
Exemplo n.º 2
0
        public virtual IActionResult Create(DoctorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDoctors))
            {
                return(AccessDeniedView());
            }

            var doctorsError = ValidateDoctors(model);

            if (!string.IsNullOrEmpty(doctorsError))
            {
                ModelState.AddModelError(string.Empty, doctorsError);
                ErrorNotification(doctorsError, false);
            }

            if (ModelState.IsValid)
            {
                var doctor = model.ToEntity <Doctor>();
                _doctorService.InsertDoctor(doctor);

                //activity log
                _customerActivityService.InsertActivity("AddNewDoctor",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewDoctor"), doctor.Id), doctor);

                SuccessNotification(_localizationService.GetResource("Hero.Admin.Doctors.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = doctor.Id }));
            }

            //prepare model
            model = _doctorModelFactory.PrepareDoctorModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }