public async Task <UserResponse> DeleteAsync(int id)
        {
            var existingUser = await _userRepository.FindByIdAsync(id);

            if (existingUser == null)
            {
                return(new UserResponse("User not found"));
            }
            try
            {
                IEnumerable <UserPlan> userPlans = await _userPlanRepository.ListByUserIdAsync(id);

                userPlans.ToList().ForEach(userPlan => {
                    _userPlanRepository.Remove(userPlan);
                });

                _userRepository.Remove(existingUser);
                await _unitOfWork.CompleteAsync();

                return(new UserResponse(existingUser));
            }
            catch (Exception ex)
            {
                return(new UserResponse($"An error ocurred while deleting user: {ex.Message}"));
            }
        }
        public async Task <IEnumerable <Plan> > ListByUserIdAsync(int userId)
        {
            var userPlan = await _userPlanRepository.ListByUserIdAsync(userId);

            var plans = userPlan.Select(up => up.Plan).ToList();

            return(plans);
        }
Example #3
0
 public async Task <IEnumerable <PlanUser> > ListByUserIdAsync(int userId)
 {
     return(await _userPlanRepository.ListByUserIdAsync(userId));
 }