public Patient ConvertToSource(PatientEditModel model)
        {
            Patient existingPatient;
            if (model.Id != 0)
            {
                var patientRepository = _unitOfWork.GetRepository<Patient>();
                existingPatient = patientRepository.FindById(model.Id);
            }
            else
                existingPatient = new Patient();

            existingPatient = ModelConverterHelper.CopyObjectProperties(model, existingPatient);

            var contact = _contactModelConverter.ConvertToSource(model.Contact);
            var profile = _profileModelConverter.ConvertToSource(model.Profile);

            var agentRepository = _unitOfWork.GetRepository<Agent>();
            var currentAgent = agentRepository.Get(x => x.UserName == model.CurrentAgent).SingleOrDefault();

            existingPatient.Id = model.Id;
            existingPatient.Contact = contact;
            existingPatient.Profile = profile;
            existingPatient.UserName = model.UserName;
            existingPatient.Agent = currentAgent;
            existingPatient.AgentId = currentAgent.Id;

            return existingPatient;
        }
コード例 #2
0
        public async Task<ActionResult> Create(PatientEditModel model)
        {
            if (ModelState.IsValid)
            {
                var patient = _modelConverter.ConvertToSource(model);
                
                var pwd = Membership.GeneratePassword(8, 2);
                var roles = new List<ApplicationRole> {ApplicationRole.Patient};
                var result = await _membershipService.CreateAsync(patient, roles, pwd);

                if (result.Succeeded)
                {
                    _mailService.SendEmailMessage("PatientCreated", new
                                                                    {
                                                                        Name = model.Profile.FullName, 
                                                                        model.UserName, 
                                                                        Password = pwd,
                                                                    }, model.Email, Constants.VanityMail, "Welcome to MyVanity", null);


                    return RedirectToAction("Index");
                }

                AddErrors(result);
            }

            return View(model);
        }
        public ActionResult PatientProfile(PatientEditModel model)
        {
            if (ModelState.IsValid)
            {
                _patientViewRepository.Update(model);
                return RedirectToAction("Dashboard");
            }

            return View(model);
        }
        public PatientEditModel ConvertToModel(Patient entity)
        {
            var contactModel = _contactModelConverter.ConvertToModel(entity.Contact);
            var profileModel = _profileModelConverter.ConvertToModel(entity.Profile);

            var patientModel = new PatientEditModel {
                Id = entity.Id,
                Contact = contactModel,
                Profile = profileModel,
                CurrentAgent = entity.Agent.UserName,
                AgentId = entity.AgentId,
                AgentName = entity.Agent.PersonDetails.FullName
            };

            patientModel = ModelConverterHelper.CopyObjectProperties(entity, patientModel);

            return patientModel;
        }
コード例 #5
0
        public ActionResult Edit(PatientEditModel model)
        {
            if (ModelState.IsValid)
            {
                _patientViewRepository.Update(model);
                return RedirectToAction("Index");
            }

            return View(model);
        }