public void ExecuteCommand(List <string> subCommands) { var shoppingItems = _shoppingRepository.GetAllItems(new Pagination { Page = 0, ResultsPerPage = int.MaxValue }, 1, true); string title; if (subCommands.Count > 0) { var discordUserId = subCommands[0].Replace("<", "").Replace("@", "").Replace(">", ""); var discordUser = _peopleRepository.GetPersonFromDiscordId(discordUserId); shoppingItems = shoppingItems.Where(x => x.AddedFor.Any(y => y.Id == discordUser.Id)).ToList(); if (shoppingItems.Count == 0) { _discordService.SendMessage(new DiscordMessage { content = "You have no shopping items!" }); return; } title = $"Shopping List for {discordUser.FirstName} {discordUser.LastName}"; } else { title = "Shopping List For All Users"; } var discordMessage = new DiscordMessage { embed = new DiscordMessageEmbed { author = new DiscordMessageAuthor { icon_url = "https://127xwr2qcfsvmn8a91nbd428-wpengine.netdna-ssl.com/wp-content/uploads/2013/01/Pile-of-salt.jpg", name = title }, fields = shoppingItems.Select(shoppingItem => new DiscordMessageField { name = $"{shoppingItem.Name}", value = $"For {string.Join(", ", shoppingItem.AddedFor.Select(x => x.FirstName))}" }).ToList() } }; _discordService.SendMessage(discordMessage); }
public GetShoppingResponse GetShoppingItems(int?page, int?resultsPerPage) { var response = new GetShoppingResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString()); if (user.HouseId == 0) { response.AddError("You must belong to a household to get shopping items", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } Pagination pagination = new Pagination { Page = page ?? 0, ResultsPerPage = resultsPerPage ?? int.MaxValue }; response.ShoppingList = _shoppingRepository.GetAllItems(pagination, user.HouseId); } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}"); } return(response); }