コード例 #1
0
        private async Task <IHttpActionResult> GetUsersByRoleIds(string email, List <string> roleIdStrList)
        {
            if (email == null)
            {
                return(BadRequest());
            }

            var proxyCreation = _db.Configuration.ProxyCreationEnabled;

            _db.Configuration.ProxyCreationEnabled = false;

            List <ApplicationUser> providers;

            providers = await _db.Users
                        .Where(u => u.Roles.Any(r => roleIdStrList.Any(rid => rid == r.RoleId)))
                        .Include(u => u.Roles)
                        .ToListAsync();

            _db.Configuration.ProxyCreationEnabled = proxyCreation;

            providers = providers.Distinct().ToList();

            foreach (var provider in providers)
            {
                if (email == provider.Email)
                {
                    return(Ok(ToDto.UserToDto(provider)));
                }
            }
            return(NotFound());
        }
コード例 #2
0
        public async Task <IHttpActionResult> GetAssignedPatients(string providerId)

        {
            var user = await _userManager.FindByIdAsync(providerId);

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

            List <ApplicationUser> patients = new List <ApplicationUser>();

            foreach (var careTeam in user.ProviderCareTeams)
            {
                if (careTeam.Active)
                {
                    patients.Add(careTeam.Patient);
                }
            }
            if (patients == null)
            {
                return(NotFound());
            }

            var usersDto = new List <UserDto>();

            foreach (var patient in patients)
            {
                usersDto.Add(ToDto.UserToDto(patient));
            }

            return(Ok(usersDto));
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetUser(string id)
        {
            var user = await _db.Users.Where(u => u.Id.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                       .Include(u => u.Roles)
                       .FirstOrDefaultAsync();

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

            return(Ok(ToDto.UserToDto(user)));
        }
コード例 #4
0
        public async Task <IHttpActionResult> PostUser(CreateUserBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var password = Randomizer.GetRandomString(10);

            var user = new ApplicationUser()
            {
                UserName    = model.FirstName + model.LastName + Randomizer.GetRandom(100000),
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Gender      = model.Gender,
                DOB         = model.DOB,
                PhoneNumber = model.PhoneNumber,
                Specialty   = model.Specialty
            };

            var identityResult = await _userManager.CreateAsync(user, password);

            if (!identityResult.Succeeded)
            {
                return(BuildErrorResult(identityResult));
            }

            Crypteron.CipherDb.Session.Unseal(user, _db);
            identityResult = await _userManager.AddToRolesAsync(user.Id, model.Roles.ToArray());


            Crypteron.CipherDb.Session.Unseal(user, _db);

            if (!identityResult.Succeeded)
            {
                return(BuildErrorResult(identityResult));
            }

            // Send an invitation to login and change password
            MailSender sender   = new MailSender();
            string     mailBody = "Dear " + user.FirstName + " " + user.LastName + ", you have been added to CloudMedic by an administrator.\n\nPlease login with your assigned username and password:\n\nUsername: "******"\nPassword: "******"\n\n After logging in, change your password under the profile tab.";

            sender.SendInvite(mailBody, user.Email);

            return(Created("users/" + user.Id, ToDto.UserToDto(user)));
        }
コード例 #5
0
        public async Task <IHttpActionResult> GetUsers(int page = 1, string role = null)
        {
            List <ApplicationUser> users;

            // Variables initialized depending on whether role specified
            int totalUsers;
            int maxPage;
            int skipUsers;

            // If no role specified, just query the last 30 users
            if (string.IsNullOrWhiteSpace(role))
            {
                totalUsers = await _db.Users.CountAsync();

                // The maximum number of pages, rounded up
                maxPage   = ((totalUsers + pageSize + 1) / pageSize);
                page      = Math.Max(1, page);
                page      = Math.Min(maxPage, page);
                skipUsers = (page - 1) * pageSize;

                users = await _db.Users
                        .OrderBy(u => u.Id)
                        .Include(u => u.Roles)
                        .Skip(skipUsers)
                        .Take(pageSize)
                        .ToListAsync();
            }
            else
            {
                var roleId = RoleManager.GetRoleIdFromRoleName(role);

                totalUsers = await _db.Users
                             .Where(u => u.Roles.Any(r => r.RoleId == roleId))
                             .CountAsync();

                // The maximum number of pages, rounded up
                maxPage   = ((totalUsers + pageSize - 1) / pageSize);
                page      = Math.Max(1, page);
                page      = Math.Min(maxPage, page);
                skipUsers = (page - 1) * pageSize;

                users = await _db.Users
                        .Where(u => u.Roles.Any(r => r.RoleId == roleId))
                        .OrderBy(u => u.Id)
                        .Include(u => u.Roles)
                        .Skip(skipUsers)
                        .Take(pageSize)
                        .ToListAsync();
            }

            UsersPageDto result = new UsersPageDto()
            {
                Users        = new List <UserDto>(),
                HasNext      = (page < maxPage),
                HasPrev      = (page > 1),
                NumPages     = maxPage,
                CurrentCount = totalUsers
            };

            // Convert the user objects to a list of serializable data transfer objects
            foreach (var user in users)
            {
                result.Users.Add(ToDto.UserToDto(user));
            }

            return(Ok(result));
        }