Example #1
0
        public IActionResult CreatePatient([FromBody] PatientDTO patient)
        {
            PatientDTO newPatient = _patientService.CreatePatient(patient);

            return(CreatedAtRoute("PatientById", new { id = newPatient.Id }, newPatient));
        }
Example #2
0
        public async Task <ServiceResponse <bool> > RegisterPatient(RegisterUser user)
        {
            var now            = DateTime.UtcNow;
            var patientAccount = await _userManager.FindByEmailAsync(user.Email);

            if (patientAccount != null)
            {
                return new ServiceResponse <bool>()
                       {
                           Data      = false,
                           IsSuccess = false,
                           Message   = $"Account with this email address {patientAccount.Email} already exist!",
                           Time      = now
                       }
            }
            ;

            if (user.Password != user.ConfirmPassword)
            {
                return new ServiceResponse <bool>()
                       {
                           Data      = false,
                           Message   = "Password Don't match",
                           Time      = now,
                           IsSuccess = false
                       }
            }
            ;

            var identityUser = new IdentityUser
            {
                Email    = user.Email,
                UserName = user.Email
            };

            var result = await _userManager.CreateAsync(identityUser, user.Password);

            var patient = new Patient
            {
                FirstName      = user.FirstName,
                LastName       = user.LastName,
                Age            = user.Age,
                IdentityNumber = user.IdentityNumber,
                Gender         = user.Gender,
                User           = identityUser
            };

            if (result.Succeeded)
            {
                await _patient.CreatePatient(patient);

                return(new ServiceResponse <bool>()
                {
                    IsSuccess = true,
                    Data = true,
                    Message = $"Successfully Registered patient. Generated Id is: {identityUser.Id}",
                    Time = now
                });
            }

            return(new ServiceResponse <bool>()
            {
                IsSuccess = false,
                Data = false,
                Message = "An error occured!",
                Time = now
            });
        }
Example #3
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User
                {
                    Email     = model.Email,
                    UserName  = model.Email,
                    BirthDate = model.BirthDate,
                    SystemId  = Guid.NewGuid()
                };
                // добавляем пользователя
                var result = await _userManager.CreateAsync(user, model.Password);

                user = await _userManager.FindByNameAsync(user.UserName);

                if (result.Succeeded)
                {
                    if (model.IsDoctor)
                    {
                        var doctor = await db.Doctors.FirstOrDefaultAsync(u => u.Email == model.Email);

                        if (doctor == null)
                        {
                            var roleName = "doctor";
                            var role     = await roleManager.FindByNameAsync(roleName);

                            if (role == null)
                            {
                                await CreateRole(roleName);

                                role = await roleManager.FindByNameAsync(roleName);
                            }
                            await _userManager.AddToRoleAsync(user, roleName);

                            //await roleManager.AddClaimAsync(role, new Claim("RoleType", roleName));
                            doctorService.CreateDoctor(new DoctorModel()
                            {
                                Id        = user.SystemId,
                                FullName  = model.FullName,
                                Email     = model.Email,
                                BirthDate = model.BirthDate,
                                Password  = model.Password
                            });
                            user = await _userManager.FindByNameAsync(user.UserName);

                            // установка куки
                            await _signInManager.SignInAsync(user, false);

                            return(RedirectToAction("Home", "Doctor"));
                        }
                    }
                    else
                    {
                        var patient = await db.Patients.FirstOrDefaultAsync(u => u.Email == model.Email);

                        if (patient == null)
                        {
                            var roleName = "patient";
                            var role     = await roleManager.FindByNameAsync(roleName);

                            if (role == null)
                            {
                                await CreateRole(roleName);

                                role = await roleManager.FindByNameAsync(roleName);
                            }
                            await _userManager.AddToRoleAsync(user, roleName);

                            //await roleManager.AddClaimAsync(role, new Claim("RoleType", roleName));
                            patientService.CreatePatient(new PatientModel()
                            {
                                Id        = user.SystemId,
                                FullName  = model.FullName,
                                Email     = model.Email,
                                BirthDate = model.BirthDate,
                                Password  = model.Password
                            });
                            user = await _userManager.FindByNameAsync(user.UserName);

                            // установка куки
                            await _signInManager.SignInAsync(user, false);

                            return(RedirectToAction("Home", "Patient"));
                        }
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
 public ActionResult CreatePatient(Patient patient)
 {
     patientService.CreatePatient(patient);
     return(RedirectToAction("Patients"));
 }
        public IHttpActionResult CreatePatient(PatientBindingModel patientBindingModel)
        {
            var patientViewModel = _patientService.CreatePatient(patientBindingModel);

            return(Ok(new ResponseModel(patientViewModel, "Аккаунт успешно создан! :)")));
        }
        public IHttpActionResult Post([FromBody] PatientDto patient)
        {
            var dto = _patientService.CreatePatient(patient);

            return(Ok(dto));
        }