예제 #1
0
        public async Task <IActionResult> GetById(Guid userId)
        {
            var user = await _userApplication.GetById(userId);

            if (user == null)
            {
                return(NotFound("Can not find user by id = " + userId));
            }

            var respone     = new UserResponse(user, _storageService);
            var sessionUser = _sessionService.GetDataFromToken();

            if (sessionUser == null)
            {
                return(BadRequest(new
                {
                    Message = "Can not read session"
                }));
            }
            //Get Follow & Favorite
            respone.Followed = await _userApplication.IsFollowed(userId, sessionUser.UserId);

            respone.Favorited = await _userApplication.IsLiked(userId, sessionUser.UserId);

            respone.Blocked = await _userApplication.GetBlockStatus(sessionUser.UserId, userId);

            var features = await _featureApplication.GetFeatureResponseByUserId(user.Id);

            respone.Features       = features.Item1;
            respone.SearchFeatures = features.Item2;
            return(Ok(respone));
        }
예제 #2
0
        public async Task <UserResponse> GetUserResponse(AppUser user)
        {
            var Features = await _featureApplication.GetFeatureResponseByUserId(user.Id);

            var userResponse = new UserResponse(user, _storageService)
            {
                Features       = Features.Item1,
                SearchFeatures = Features.Item2
            };

            return(userResponse);
        }
예제 #3
0
        public async Task <IActionResult> Login([FromForm] LoginRequest request)
        {
            var user = await _context.Users
                       .Where(x => x.Email == request.Email.Trim()).FirstOrDefaultAsync();

            if (user == null)
            {
                return(BadRequest(new
                {
                    Message = "Tên đăng nhập hoặc mật khẩu không chính xác!"
                }));
            }

            if (user.TypeAccount != ETypeAccount.System)
            {
                return(BadRequest(new
                {
                    Message = "Vui lòng đăng nhập với tài khoản " + user.TypeAccount.ToString()
                }));
            }

            if (user.PassWord != request.Password.Trim())
            {
                return(BadRequest(new
                {
                    Message = "Tên đăng nhập hoặc mật khẩu không chính xác!"
                }));
            }

            if (user.Status == EUserStatus.IsVerifying)
            {
                var info = new LoginInfo()
                {
                    Email           = user.Email,
                    FullName        = user.FullName,
                    IsMailConfirmed = false,
                    Message         = MessageMail.VerifyMail,
                    UserId          = user.Id,
                    UserName        = user.UserName
                };

                return(BadRequest(new
                {
                    Message = MessageMail.VerifyMail
                }));
            }

            if (user.Status == EUserStatus.Inactive)
            {
                return(BadRequest(new
                {
                    Message = "Tài khoản của bạn đã bị khóa bởi quản trị viên!"
                }));
            }

            if (!await _featureApplication.CheckUserFeature(user.Id))
            {
                user.IsInfoUpdated = false;
            }

            var userResponse = new UserResponse(user, _storageService);
            var ft           = await _featureApplication.GetFeatureResponseByUserId(userResponse.Id);

            userResponse.Features       = ft.Item1;
            userResponse.SearchFeatures = ft.Item2;
            userResponse.Token          = this.GenerateJSONWebToken(user);

            return(Ok(userResponse));
        }
        private async Task <List <UserResponse> > FilterFeatures(List <FilterFeaturesRequest> requests)
        {
            List <EGender>   genders   = new List <EGender>();
            List <ELocation> locations = new List <ELocation>();
            List <EJob>      jobs      = new List <EJob>();
            List <EAgeGroup> ageGroups = new List <EAgeGroup>();
            List <Filter>    filters   = new List <Filter>();

            foreach (FilterFeaturesRequest item in requests)
            {
                switch (item.FeatureId)
                {
                case -1:
                    ageGroups.Add((EAgeGroup)item.ValueId);
                    break;

                case -2:
                    genders.Add((EGender)item.ValueId);
                    break;

                default:
                    if (!filters.Any(x => x.FeatureId == item.FeatureId))
                    {
                        filters.Add(new Filter()
                        {
                            FeatureId = item.FeatureId, ValueId = new List <int>()
                        });
                    }

                    filters.First(x => x.FeatureId == item.FeatureId).ValueId.Add(item.ValueId);

                    break;
                }
            }

            var us = await _context.Users.Where(x => x.Status == EUserStatus.Active && x.IsInfoUpdated).ToListAsync();

            List <AppUser> filterUsers = new List <AppUser>();

            if (genders.Count > 0)
            {
                foreach (EGender item in genders)
                {
                    var filter = us.Where(x => x.Gender == item).ToList();
                    filterUsers = filterUsers.Concat(filter)
                                  .ToList();
                }
                us          = filterUsers;
                filterUsers = new List <AppUser>();
            }


            if (ageGroups.Count > 0)
            {
                foreach (EAgeGroup item in ageGroups)
                {
                    var filter = us.Where(x => _userApplication.GetAgeGroup(x.Dob) == item).ToList();
                    filterUsers = filterUsers.Concat(filter)
                                  .ToList();
                }
                us          = filterUsers;
                filterUsers = new List <AppUser>();
            }


            var users = (from i in us
                         select new UserResponse(i, _storageService)
                         ).ToList();

            foreach (var item in users)
            {
                var features = await _featureApplication.GetFeatureResponseByUserId(item.Id);

                item.Features = features.Item1;
                //item.SearchFeatures = features.Item2;
            }

            foreach (var i in filters)
            {
                var fUsers = new List <UserResponse>();
                foreach (var j in i.ValueId)
                {
                    foreach (var t in users)
                    {
                        foreach (var y in t.Features)
                        {
                            if (y.FeatureId == i.FeatureId && y.FeatureDetailId == j)
                            {
                                fUsers.Add(t);
                            }
                        }
                    }
                }

                users = users.Intersect(fUsers).ToList();
            }

            return(users);
        }
예제 #5
0
        public async Task <IActionResult> Login([FromForm] LoginRequest request)
        {
            var user = await _context.Users
                       .Where(x => x.Email == request.Email.Trim()).FirstOrDefaultAsync();

            if (user == null)
            {
                return(BadRequest(new
                {
                    Message = "UserName or Password is not correct!"
                }));
            }

            if (user.TypeAccount != ETypeAccount.System)
            {
                return(BadRequest(new
                {
                    Message = "Please login with " + user.TypeAccount.ToString()
                }));
            }

            if (user.PassWord != request.Password.Trim())
            {
                return(BadRequest(new
                {
                    Message = "UserName or Password is not correct!"
                }));
            }

            if (user.Status == EUserStatus.IsVerifying)
            {
                var info = new LoginInfo()
                {
                    Email           = user.Email,
                    FullName        = user.FullName,
                    IsMailConfirmed = false,
                    Message         = MessageMail.VerifyMail,
                    UserId          = user.Id,
                    UserName        = user.UserName
                };

                return(BadRequest(new
                {
                    Message = MessageMail.VerifyMail
                }));
            }

            if (user.Status == EUserStatus.Inactive)
            {
                return(BadRequest(new
                {
                    Message = "Your account has been locked!"
                }));
            }

            if (!await _featureApplication.CheckUserFeature(user.Id))
            {
                user.IsInfoUpdated = false;
            }

            var userResponse = new UserResponse(user, _storageService);
            var ft           = await _featureApplication.GetFeatureResponseByUserId(userResponse.Id);

            userResponse.Features       = ft.Item1;
            userResponse.SearchFeatures = ft.Item2;
            userResponse.Token          = this.GenerateJSONWebToken(user);

            return(Ok(userResponse));
        }