예제 #1
0
        public async Task <GetMemberRs> GetCurrentUser()
        {
            GetMemberRs rs = new GetMemberRs();

            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                rs.IsAuthenticated = false;
                rs.Member          = null;
            }
            else
            {
                int userId = int.Parse(HttpContext.Current.User.Identity.GetUserId());

                var user = await _dbContext.Users
                           .Where(x => x.Id == userId)
                           .ProjectTo <MemberDTO>(_mappingConfig, dest => dest.Membership)
                           .FirstOrDefaultAsync();

                if (user != null)
                {
                    user.RoleNames = new List <string>(await _userManager.GetRolesAsync(userId));
                    rs.Member      = user;

                    rs.IsAuthenticated = true;
                }
                else
                {
                    rs.IsAuthenticated = false;
                }
            }

            return(rs);
        }
예제 #2
0
        public async Task <GetMemberRs> Get(GetMemberRq rq)
        {
            bool   isMember        = HttpContext.Current.User.IsInRole("Member");
            string currentUserName = HttpContext.Current.User.Identity.GetUserName();

            if (isMember && currentUserName != rq.UserName)
            {
                throw new Exception("Not found");
            }

            GetMemberRs rs = new GetMemberRs();

            var query = _dbContext.Users.ProjectTo <MemberDTO>(_mappingConfig, dest => dest.Membership, dest => dest.RegisteredBranch);

            if (!string.IsNullOrEmpty(rq.UserName))
            {
                rs.Member = await query.FirstOrDefaultAsync(u => u.UserName == rq.UserName);
            }
            else if (!string.IsNullOrEmpty(rq.PhoneNumber))
            {
                rs.Member = await query.FirstOrDefaultAsync(u => u.PhoneNumber == rq.PhoneNumber);
            }

            return(rs);
        }