コード例 #1
0
        public void Create(DentistDTO dentistDTO)
        {
            var dentist = DentistMapper.DTOtoApplicationUser(dentistDTO);
            PasswordHasher <ApplicationUser> passwordHasher = new PasswordHasher <ApplicationUser>();
            var passwordHash = passwordHasher.HashPassword(dentist, dentistDTO.Password);

            dentist.PasswordHash = passwordHash;

            _context.ApplicationUsers.Add(dentist);

            var role = _context.ApplicationRole.Where(r => r.Name.Equals("Dentist")).Single();

            dentist.UserRoles.Add(new ApplicationUserRole()
            {
                User = dentist,
                Role = role,
            });

            var userId = _userProviderService.GetUserId();

            var affiliateId = _context.ApplicationUsers
                              .Where(u => u.Id.Equals(userId))
                              .Select(u => u.AffiliateId)
                              .Single();

            var affiliate = _context.Affiliates.Find(affiliateId);

            dentist.Affiliate = affiliate;

            _context.SaveChanges();
        }
コード例 #2
0
        public ActionResult <DentistViewModel> GetCurrentDentist()
        {
            var dentist = _service.GetCurrent();

            if (dentist == null)
            {
                return(NotFound());
            }

            return(DentistMapper.DTOtoDentistViewModel(dentist));
        }
コード例 #3
0
        public DentistDTO Get(string id)
        {
            var applicationUser = _context.ApplicationUsers
                                  .Include(ur => ur.UserRoles)
                                  .ThenInclude(r => r.Role)
                                  .Include(a => a.Affiliate)
                                  .SingleOrDefault(x => x.Id.Equals(id));

            if (applicationUser == null)
            {
                return(null);
            }

            return(DentistMapper.ApplicationUserToDTO(applicationUser));
        }
コード例 #4
0
        public DentistDTO GetCurrent()
        {
            var userId = _userProviderService.GetUserId();

            var applicationUser = _context.ApplicationUsers
                                  .Include(ur => ur.UserRoles)
                                  .ThenInclude(r => r.Role)
                                  .Include(a => a.Affiliate)
                                  .SingleOrDefault(x => x.Id.Equals(userId));

            if (applicationUser == null)
            {
                return(null);
            }

            return(DentistMapper.ApplicationUserToDTO(applicationUser));
        }
コード例 #5
0
        public IActionResult UpdateDentist(string id, [FromBody] UpdateDentistViewModel updateDentistViewModel)
        {
            if (id != updateDentistViewModel.Id)
            {
                return(BadRequest());
            }

            if (!_service.Exist(id))
            {
                return(NotFound());
            }

            var dentalDTO = DentistMapper.UpdateDentistViewModelToDTO(updateDentistViewModel);

            _service.Update(dentalDTO);

            return(NoContent());
        }
コード例 #6
0
        public List <DentistDTO> GetAll()
        {
            var userId = _userProviderService.GetUserId();

            var affiliateId = _context.ApplicationUsers
                              .Where(u => u.Id.Equals(userId))
                              .Select(u => u.AffiliateId)
                              .Single();

            var dentists = _context.ApplicationUsers
                           .Include(ur => ur.UserRoles)
                           .ThenInclude(r => r.Role)
                           .Where(r => r.UserRoles.Any(r => r.Role.Name.Equals("Dentist")))
                           .Include(a => a.Affiliate)
                           .Where(a => a.Affiliate.Id.Equals(affiliateId))
                           .Select(x => DentistMapper.ApplicationUserToDTO(x))
                           .ToList();

            return(dentists);
        }
コード例 #7
0
        public IActionResult CreateDentist([FromBody] CreateDentistViewModel createDentistViewModel)
        {
            if (_service.GetByUsername(createDentistViewModel.Email) != null)
            {
                ModelState.AddModelError(nameof(createDentistViewModel.Email), "This email is already taken");
                return(BadRequest(ModelState));
            }

            if (!PasswordChecker.ValidatePassword(createDentistViewModel.Password, out var message))
            {
                ModelState.AddModelError(nameof(createDentistViewModel.Password), message);
                return(BadRequest(ModelState));
            }

            var dentalDTO = DentistMapper.AddDentistViewModelToDTO(createDentistViewModel);

            _service.Create(dentalDTO);

            return(Ok(ModelState));
        }
コード例 #8
0
 public ActionResult <IEnumerable <DentistViewModel> > GetDentists()
 {
     return(_service.GetAll().Select(x => DentistMapper.DTOtoDentistViewModel(x)).ToArray());
 }