Exemple #1
0
        public async Task<ActionResult> Edit(int id, DoctorChangeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var doctor = await _doctorService.GetByIdAsync(id);
                if (doctor == null)
                {
                    return HttpNotFound();
                }

                var user = await _userManager.FindByIdAsync(doctor.UserId);
                if (user == null)
                {
                    return HttpNotFound();
                }

                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.MiddleName = model.MiddleName;
                user.Email = model.Email;
                user.AvatarUrl = model.AvatarUrl;

                var identityResult = await _userManager.UpdateAsync(user);
                if (identityResult.Succeeded)
                {
                    doctor.SpecializationId = model.SpecializationId;
                    doctor.Description = model.Description;
                    await _doctorService.UpdateAsync(doctor);

                    return RedirectToAction("Index");
                }

                foreach (var identityError in identityResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, identityError);
                }
            }

            var specializations = await _doctorService.GetSpecializationsAsync();
            ViewBag.Specializations = specializations.Select(t => new SelectListItem
            {
                Text = t.DisplayName,
                Value = t.Id.ToString()
            });

            return View(model);
        }
Exemple #2
0
        public async Task<ActionResult> Edit(int id)
        {
            var doctor = await _doctorService.GetByIdAsync(id);
            if (doctor == null)
            {
                return HttpNotFound("doctor not found");
            }

            var specializations = await _doctorService.GetSpecializationsAsync();
            ViewBag.Specializations = specializations.Select(t => new SelectListItem
            {
                Text = t.DisplayName,
                Value = t.Id.ToString(),
                Selected = t.Id == doctor.SpecializationId
            });

            var doctorViewModel = new DoctorChangeViewModel
            {
                Id = doctor.Id,
                Email = doctor.User.Email,
                FirstName = doctor.User.FirstName,
                LastName = doctor.User.LastName,
                MiddleName = doctor.User.MiddleName,
                SpecializationId = doctor.SpecializationId,
                Description = doctor.Description
            }; 

            return View(doctorViewModel);
        }