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 void ExecuteCommand(List <string> subCommands) { // Only works for first household var allBills = _billRepository.GetAllBasicBillDetails(new Pagination { Page = 0, ResultsPerPage = int.MaxValue }, 1); var outstandingBills = allBills.Where(x => x.AmountPaid < x.TotalAmount).ToList(); outstandingBills.Reverse(); if (subCommands.Count > 0) { var discordUserId = subCommands[0].Replace("<", "").Replace("@", "").Replace(">", ""); var discordUser = _peopleRepository.GetPersonFromDiscordId(discordUserId); outstandingBills = outstandingBills.Where(x => x.People.Any(y => y.Id == discordUser.Id)).ToList(); var billsForDiscordUser = new List <Bill>(); foreach (var bill in outstandingBills) { var paymentsForUser = bill.Payments.Where(x => x.Person.Id == discordUser.Id); var totalPaid = paymentsForUser.Sum(x => x.Amount); if (totalPaid + 0.01m < bill.TotalAmount / bill.People.Count) { billsForDiscordUser.Add(bill); } } if (billsForDiscordUser.Count == 0) { _discordService.SendMessage(new DiscordMessage { content = "You have no outstanding bills!" }); return; } var discordMessage = new DiscordMessage { embed = new DiscordMessageEmbed { author = new DiscordMessageAuthor { icon_url = discordUser.Image, name = discordUser.FirstName + " " + discordUser.LastName }, title = "Outstanding Bills For " + discordUser.FirstName + " " + discordUser.LastName, fields = billsForDiscordUser.Select(x => new DiscordMessageField { name = x.Name, value = $"`[{x.FullDateDue:MMM dd}]` £{x.TotalAmount}" }).ToList() } }; _discordService.SendMessage(discordMessage); return; } if (outstandingBills.Count == 0) { _discordService.SendMessage(new DiscordMessage { content = "You have no outstanding bills!" }); return; } var discordMessage2 = 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 = "Salt Automaton" }, title = "Outstanding Bills For All Users", fields = outstandingBills.Select(x => new DiscordMessageField { name = $"{x.Name} - {x.FullDateDue:dd MMMM}", value = $"£{x.TotalAmount}" }).ToList() } }; _discordService.SendMessage(discordMessage2); }