public async Task <List <Profile> > Handle(Query request, CancellationToken cancellationToken) { // handler logic goes here var queryable = _context.Followings.AsQueryable(); var userFollowings = new List <UserFollowing>(); var profiles = new List <Profile>(); switch (request.Predicate) { case "followers": { userFollowings = await queryable.Where(x => x.Target.UserName == request.Username).ToListAsync(); foreach (var follower in userFollowings) { profiles.Add(await _profileReader.ReadProfile(follower.Observer.UserName)); } break; } case "following": { userFollowings = await queryable.Where(x => x.Observer.UserName == request.Username).ToListAsync(); foreach (var follower in userFollowings) { profiles.Add(await _profileReader.ReadProfile(follower.Target.UserName)); } break; } } return(profiles); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { // var user = await _context.Users.SingleOrDefaultAsync(x => // x.UserName == request.Username); // return new Profile // { // DisplayName = user.DisplayName, // Username = user.UserName, // Image = user.Photos.FirstOrDefault(x => x.IsMain)?.Url, // Photos = user.Photos, // Bio = user.Bio // }; return(await _profileReader.ReadProfile(request.Username)); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { // var user = await _context.Users.SingleOrDefaultAsync(u => u.UserName == request.Username); // if (user == null) // throw new RestException(HttpStatusCode.NotFound, new { User = $"User {request.Username} not found" }); // return new Profile // { // DisplayName = user.DisplayName, // Username = user.UserName, // Image = user.Photos.FirstOrDefault(x => x.IsMain)?.Url, // Photos = user.Photos, // Bio = user.Bio // }; return(await _profileReader.ReadProfile(request.Username)); }
/* * private readonly DataContext _context; * public Handler (DataContext context) { * _context = context; * } */ public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { return(await _profileReader.ReadProfile(request.Username)); //handler logic goes here /* var user = await _context.Users.SingleOrDefaultAsync ( * x => x.UserName == request.Username //in the Query: IRequest<Profile> * ); * * return new Profile { * DisplayName = user.DisplayName, * Username = user.UserName, * Image = user.Photos.FirstOrDefault (x => x.IsMain)?.Url, * Photos = user.Photos, * Bio = user.Bio * }; */ }
public async Task <Profile> Handle(Command request, CancellationToken cancellationToken) { var currentUser = await _context.Users.SingleOrDefaultAsync(u => u.UserName == _userAccessor.GetCurrentUsername()); var userToFollow = await _context.Users.SingleOrDefaultAsync(u => u.UserName == request.Username); if (currentUser.UserName == userToFollow.UserName) { throw new RestException(HttpStatusCode.NotFound, new { User = "******" }); } if (userToFollow == null) { throw new RestException(HttpStatusCode.NotFound, new { User = "******" }); } var following = await _context.UserFollowings.FindAsync(currentUser.Id, userToFollow.Id); if (following != null) { throw new RestException(HttpStatusCode.BadRequest, new { User = "******" }); } //else create new following following = new UserFollowing { User = currentUser, UserToFollow = userToFollow }; _context.UserFollowings.Add(following); var IsSuccessful = await _context.SaveChangesAsync() > 0; if (IsSuccessful) { return(await _profileReader.ReadProfile(currentUser.UserName)); } throw new Exception("Problem"); }
public async Task <ProfileEnvelope> Handle(Command message, CancellationToken cancellationToken) { var target = await _context.Persons.FirstOrDefaultAsync(x => x.Username == message.Username, cancellationToken); if (target == null) { throw new RestException(HttpStatusCode.NotFound, new { User = Constants.NOT_FOUND }); } var observer = await _context.Persons.FirstOrDefaultAsync(x => x.Username == _currentUserAccessor.GetCurrentUsername(), cancellationToken); var followedPeople = await _context.FollowedPeople.FirstOrDefaultAsync(x => x.ObserverId == observer.PersonId && x.TargetId == target.PersonId, cancellationToken); if (followedPeople != null) { _context.FollowedPeople.Remove(followedPeople); await _context.SaveChangesAsync(cancellationToken); } return(await _profileReader.ReadProfile(message.Username)); }
public async Task <ProfileDto> Handle(Command request, CancellationToken cancellationToken) { Guid appUserId = _userAccessor.GetCurrentUserId(); await Validate(appUserId, request, cancellationToken); UserFollower userFollower = new UserFollower { UserId = request.FollowingUserId, FollowerId = appUserId }; _unitOfWork.UserFollowerRepo.Add(userFollower); int insertCnt = await _unitOfWork.SaveAsync(cancellationToken); if (insertCnt > 0) { return(await _profileReader.ReadProfile(appUserId, cancellationToken)); } throw new Exception("Problem saving changes to database"); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) => await profileReader.ReadProfile(request.UserName);
public async Task <ProfileEnvelope> Handle(Query message, CancellationToken cancellationToken) { return(await _profileReader.ReadProfile(message.Username)); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { return(await _profileReader.ReadProfile(request.Username)); }
public async Task <Result <Profile> > Handle(Query request, CancellationToken cancellationToken) { var mappedProfile = await _profileReader.ReadProfile(request.Username); return(Result <Profile> .Success(mappedProfile)); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { // handler logic goes here return(await _profileReader.ReadProfile(request.UserName)); }
public async Task <Profile> Handle(Query request, CancellationToken cancellationToken) { return(await profileReader.ReadProfile(request.UserName)); throw new Exception("Problem in profile-details handler"); }
public async Task <ProfileDto> Handle(Query request, CancellationToken cancellationToken) { return(await _profileReader.ReadProfile(request.AppUserId, cancellationToken)); }
public async Task <ProfileEnvelope> Handle(Query message) { return(await _profileReader.ReadProfile(message.Username)); }
public async Task <UserProfileDto> Handle(Query request, CancellationToken cancellationToken) { //Handler logic return(await _profileReader.ReadProfile(request.UserName)); }