Example #1
0
        public async Task <IActionResult> GetMe()
        {
            try
            {
                var jwtPayloadInfo = this.GetJwtPayloadInfo();

                var existingUserProfile = await _bl.GetUserProfile_byExtRefIdAsync(jwtPayloadInfo.ExtReferenceId);

                if (existingUserProfile == null)
                {
                    return(this.ApiErrorMessage404NotFound($"UserId {jwtPayloadInfo.ExtReferenceId} not found"));
                }
                else
                {
                    var response = new UserProfileResponseInfo
                    {
                        Email                   = existingUserProfile.PrimaryEmail,
                        EnrolledModules         = new string[] { "LC90Module" },
                        FirstName               = _bl.GetStringWithFirstCharacterUpper(existingUserProfile.FirstName),
                        LastName                = existingUserProfile.LastName,
                        Status                  = getStatus(),
                        Indexes                 = getIndexes(),
                        PartnerInvitationStatus = EnumMapper.From(existingUserProfile.PartnerInvitationStatus)
                    };

                    UserProfileStatusType getStatus()
                    {
                        if (existingUserProfile.IsOnboardingQuesitonnaireCompleted())
                        {
                            return(UserProfileStatusType.Complete);
                        }

                        if (existingUserProfile.IsRegistrationCompleted())
                        {
                            return(UserProfileStatusType.Pending);
                        }
                        else
                        {
                            return(UserProfileStatusType.New);
                        }
                    }

                    List <UserIndex> getIndexes()
                    {
                        var r = new List <UserIndex>();

                        if (existingUserProfile?.Indexes != null)
                        {
                            foreach (var i in existingUserProfile.Indexes)
                            {
                                var index = IndexType.Unknown;
                                if (!Enum.TryParse <IndexType>(i.TypeOfIndex.ToString(), out index))
                                {
                                    //TODO: Log the fact that converting this enum value failed, as a Warning
                                }
                                r.Add(new UserIndex {
                                    TypeOfIndex = index, Value = i.Value
                                });
                            }
                        }
                        return(r);
                    }

                    return(Json(response));
                }
            }
            catch (Exception exc)
            {
                return(BadRequest(exc));
            }
        }