示例#1
0
        public string GetRecommendUser([FromBody] QueryGetRecommend query)
        {
            query.Ssid = query.Ssid.Substring(1, query.Ssid.Length - 2);
            var json = new UserRecommend().GetRecommendInfo(query);

            return(JsonConvert.SerializeObject(json));
        }
示例#2
0
        public int AddRecommend(UserRecommend eneity)
        {
            var query = GetAll();
            var item  = query.Where(o => o.Recommended == eneity.Recommended).FirstOrDefault();

            if (item == null)
            {
                eneity.JoinTime = DateTime.Now;
                return(InsertAndGetId(eneity));
            }
            return(0);
        }
示例#3
0
        public async Task <ActionResult> AddRecommend(string username)
        {
            var sourceUserId    = User.GetUserId();
            var recommendedUser = await _userRepository.GetUserByUsernameAsync(username);

            var sourceUser = await _recommendationsRepository.GetUserWithRecommendations(sourceUserId);

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

            if (sourceUser.UserName == username)
            {
                return(BadRequest("You cannot recommend yourself"));
            }

            var userRecommend = await _recommendationsRepository.GetUserRecommend(sourceUserId, recommendedUser.Id);

            if (userRecommend != null)
            {
                return(BadRequest("You already recommended this user"));
            }

            userRecommend = new UserRecommend
            {
                SourceUserId      = sourceUserId,
                RecommendedUserId = recommendedUser.Id
            };

            sourceUser.RecommendedUsers.Add(userRecommend);

            if (await _userRepository.SaveAllAsync())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user"));
        }
示例#4
0
 public bool DeleteEntity(UserRecommend entity)
 {
     return(base.DeleteEntity <UserRecommend>(entity));
 }
示例#5
0
 public bool UpdateEntity(UserRecommend entity)
 {
     return(base.UpdateEntity <UserRecommend>(entity));
 }