public bool HandleRequest(Client client, HttpListenerContext context, params string[] args) { if (!UserManager.Connected(client)) { context.Send("not connected"); return(true); } User user = UserManager.GetUser(UserManager.GetUserID(client)); if (user == null) { context.Send("user not found"); return(true); } if (args.Length > 0) { switch (args[0]) { case "me": context.Send(JsonConvert.SerializeObject(UserResponse.FromUser(user))); break; } } return(true); }
public static UserResponse[] ToResponse(this User[] users) { List <UserResponse> responses = new List <UserResponse>(); foreach (User user in users) { responses.Add(UserResponse.FromUser(user)); } return(responses.ToArray()); }
public async Task <TransactionsListResponse> GetTransactions(string userId, PaginationFilter filter) { TransactionsListResponse result = new TransactionsListResponse(); var account = await GetAccount(userId); var query = Context.Transactions.Where(t => t.ToAccountId == account.Id || t.FromAccountId == account.Id); result.TotalCount = await query.CountAsync(); if (filter != null) { if (filter.Skip.HasValue) { var skip = filter.Skip.Value; query = query.Skip(skip); result.Skipped = skip; } if (filter.Take.HasValue) { var take = filter.Take.Value; query = query.Take(take); result.Taken = take; } } result.List = await query .Include(p => p.FromAccount).ThenInclude(a => a.Owner) .Include(p => p.ToAccount).ThenInclude(a => a.Owner) .OrderBy(t => t.Created) .Select(t => new TransactionResponse { Id = t.Id, Amount = t.Amount, Created = t.Created, TransactionType = t.TransactionType, Comment = t.Comment, FromUser = UserResponse.FromUser(t.FromAccount.Owner), ToUser = UserResponse.FromUser(t.ToAccount.Owner), Balance = t.Balance }).ToListAsync(); return(result); }
public async Task <UsersListResponse> GetUsersList(UsersListFilter filter) { UsersListResponse result = new UsersListResponse(); var query = Context.Users.AsQueryable(); if (!string.IsNullOrWhiteSpace(filter?.IgnoreUserId)) { query = query.Where(u => u.Id != filter.IgnoreUserId); } if (!string.IsNullOrWhiteSpace(filter?.Text)) { var text = filter.Text; query = query.Where(u => u.FirstName.Contains(text) || u.LastName.Contains(text) || u.UserName.Contains(text) || u.Email.Contains(text) || u.PhoneNumber.Contains(text)); } result.TotalCount = await query.CountAsync(); if (filter != null) { if (filter.Skip.HasValue) { var skip = filter.Skip.Value; query = query.Skip(skip); result.Skipped = result.TotalCount > 0 ? skip : 0; } if (filter.Take.HasValue) { var take = filter.Take.Value; query = query.Take(take); result.Taken = result.TotalCount > 0 ? take : 0; } } result.List = await query.Select(u => UserResponse.FromUser(u)).ToListAsync(); return(result); }