public async Task <IActionResult> GetReferrals()
        {
            var email = _userManager.GetUserId(HttpContext.User);
            var user  = await _userManager.FindByEmailAsync(email);

            var referral_models = new List <ReferralModel>();

            if (await _userManager.IsInRoleAsync(user, "client"))
            {
                var profile   = _profileService.Get().FirstOrDefault(e => e.user_id == user.Id);
                var referrals = _referralService.Get().Where(e => e.profile_id == profile.id)
                                .Include(e => e.clinician_)
                                .Include(e => e.profile_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_type_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_activity_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_activity_sub_);



                foreach (var referral in referrals)
                {
                    referral_models.Add(new ReferralModel(referral));
                }

                return(Ok(referral_models));
            }
            else if (await _userManager.IsInRoleAsync(user, "clinician"))
            {
                var clinician = _clinicianService.Get().FirstOrDefault(e => e.user_id == user.Id);

                var referrals = _referralService.Get().Where(e => e.clinician_id == clinician.id)
                                .Include(e => e.clinician_)
                                .Include(e => e.profile_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_type_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_activity_)
                                .Include(e => e.profile_match_).ThenInclude(e => e.appointment_activity_sub_);

                foreach (var referral in referrals)
                {
                    referral_models.Add(new ReferralModel(referral));
                }

                return(Ok(referral_models));
            }



            return(Ok(referral_models));
        }
        public async Task <IActionResult> Referrals(int?page, string query = null)
        {
            int pageSize = 25;

            ViewBag.query = query;
            var referrals = _referralService.Get();

            if (User.IsInRole("client"))
            {
                var user_id = _userManager.GetUserId(HttpContext.User);
                var profile = _profileService.Get().FirstOrDefault(e => e.user_id == user_id);

                referrals = referrals.Where(e => e.profile_id == profile.id);
            }
            else if (User.IsInRole("clinician"))
            {
                var user_id   = _userManager.GetUserId(HttpContext.User);
                var clinician = _clinicianService.Get().FirstOrDefault(e => e.user_id == user_id);

                referrals = referrals.Where(e => e.clinician_id == clinician.id);
            }
            if (!string.IsNullOrEmpty(query))
            {
                referrals = referrals.Where(e => e.id.ToString().Contains(query) || (e.clinician_.first_name != null && e.clinician_.first_name.Contains(query)) || (e.clinician_.last_name != null && e.clinician_.last_name.Contains(query)) || (e.profile_.first_name != null && e.profile_.first_name.Contains(query)) || (e.profile_.last_name != null && e.profile_.last_name.Contains(query)));
            }
            return(View(await PaginatedList <mp_referral> .CreateAsync(referrals.Include(e => e.profile_).Include(e => e.clinician_).Include(e => e.profile_match_).OrderByDescending(e => e.created_at).AsNoTracking(), page ?? 1, pageSize)));
        }
Beispiel #3
0
        public async Task <IActionResult> Referral(string code)
        {
            var model = new ReferralViewModel {
                Code = code, CodeIsValid = true
            };

            if (!Guid.TryParse(code, out Guid referralCode))
            {
                model.CodeIsValid = false;
                return(View(code));
            }

            var referral = await ReferralService.Get(referralCode);

            if (referral == null)
            {
                model.CodeIsValid = false;
                return(View(model));
            }

            model.Email = referral.Email;

            return(View(model));
        }
 public Referral Get(long id)
 {
     return(_referralService.Get(id));
 }