public async Task <IHttpActionResult> GetCareTeam(Guid id)
        {
            CareTeam careTeam = await db.CareTeam.FindAsync(id);

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

            var roles = await db.Roles.ToDictionaryAsync(r => r.Id);

            return(Ok(ToDto.CareTeamToDto(careTeam, roles)));
        }
Exemple #2
0
        public async Task <IHttpActionResult> GetPatientCareTeams(string id)
        {
            var user = await _userManager.FindByIdAsync(id);

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

            var careTeamsDto = new List <CareTeamDto>();
            var roles        = await _db.Roles.ToDictionaryAsync(r => r.Id);

            foreach (var careTeam in user.PatientCareTeams)
            {
                careTeamsDto.Add(ToDto.CareTeamToDto(careTeam, roles));
            }

            return(Ok(careTeamsDto));
        }
        public async Task <IHttpActionResult> GetCareTeams()
        {
            List <CareTeam> careTeams;

            //TODO: Add pagination to support over 30 care teams
            careTeams = await db.CareTeam
                        .Take(30)
                        .ToListAsync();

            var careTeamsDto = new List <CareTeamDto>();

            var roles = await db.Roles.ToDictionaryAsync(r => r.Id);

            foreach (var careTeam in careTeams)
            {
                careTeamsDto.Add(ToDto.CareTeamToDto(careTeam, roles));
            }

            return(Ok(careTeamsDto));
        }
        public async Task <IHttpActionResult> PostCareTeam(CareTeamBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = await userManager.FindByIdAsync(model.PatientId);

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

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

            foreach (string ProviderId in model.ProviderIds)
            {
                var provider = await userManager.FindByIdAsync(ProviderId);

                if (provider == null)
                {
                    return(NotFound());
                }
                providers.Add(provider);
            }

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

            foreach (string SupporterId in model.SupporterIds)
            {
                var supporter = await userManager.FindByIdAsync(SupporterId);

                if (supporter == null)
                {
                    return(NotFound());
                }
                supporters.Add(supporter);
            }

            var careTeam = new CareTeam()
            {
                Id         = Guid.NewGuid(),
                Name       = model.Name,
                Active     = false,
                Providers  = providers,
                Supporters = supporters,
                Patient    = patient
            };

            db.CareTeam.Add(careTeam);
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CareTeamExists(careTeam.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created("CareTeams/" + careTeam.Id, ToDto.CareTeamToDto(careTeam)));
        }