Пример #1
0
        public async Task <IActionResult> RegisterDoctor(RegisterDoctorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = new ApplicationUser
            {
                UserName = model.Name,
                IsActive = true
            };

            var createUserResult = await _userManager.CreateAsync(user, model.Password);

            if (createUserResult.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, "Doctor");

                await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.GivenName, model.Name));

                var signInResult = await _signInManager.PasswordSignInAsync(user, model.Password, false, false);

                if (signInResult.Succeeded)
                {
                    await _specializationsRepository.AddSpecialization(
                        new Specialization
                    {
                        Name = model.Specialization
                    });

                    var docsSpec = await _specializationsRepository.GetSpecializationByUserName(model.Specialization);

                    var doctor = new Doctor
                    {
                        Name              = model.Name,
                        FirstName         = model.FirstName,
                        LastName          = model.LastName,
                        Phone             = model.Phone,
                        Specialization    = docsSpec,
                        ApplicationUserID = user.Id
                    };

                    await _doctorsRepository.AddDoctor(doctor);

                    return(View("RegisterSuccessful"));
                }
            }

            foreach (var identityError in createUserResult.Errors)
            {
                ModelState.AddModelError("", identityError.Description);
            }

            return(View(model));
        }
        public IActionResult Post([FromBody] Doctor doctor)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var createdDoctor = doctors.AddDoctor(doctor);

            return(CreatedAtAction(nameof(Get), new { id = createdDoctor.Id }, createdDoctor));
        }
Пример #3
0
 public void Post([FromBody] Doctor doctor)
 {
     //doctors.Add(doctor);
     _doctorRepository.AddDoctor(doctor);
 }