public static void SetAgentNextBid(string slackUser, int amount, SlackClient agentClient) { lock (ServiceLock) { using (var db = new SlackLeadsBidderContext()) { var agent = db.Agents.FirstOrDefault(e => e.SlackId == slackUser); if (agent == null) { agentClient.PostError($"No agent configured for '{slackUser}'"); return; } var availableCredits = db.Transactions .Where(e => e.Agent.SlackId == slackUser) .Sum(e => (int?)e.Amount) ?? 0; if (availableCredits < amount) { agentClient.PostError($"You don't have enough credits. You're balance is {availableCredits}."); return; } agent.NextBid = amount; db.SaveChanges(); var slackClient = new SlackClient(SlackLeadsBidderSettings.Settings.SlackOutgoingWebhook); slackClient.Post(new SlackMessage() { Text = $"Agent @{slackUser} changed bid to {amount}." }); } } }
public void Balance(SlackCommandRequest request) { var settings = SlackLeadsBidderSettings.Settings; var agentClient = new SlackClient(request.Response_Url); if (request.Token != settings.SlackCommandBalanceToken) { agentClient.PostError("Invalid token."); } SlackLeadsBidderService.ShowBalance(agentClient); }
public static void GetAgentAutoBid(string slackUser, SlackClient agentClient) { using (var db = new SlackLeadsBidderContext()) { var agent = db.Agents.FirstOrDefault(e => e.SlackId == slackUser); if (agent == null) { agentClient.PostError($"No agent configured for '{slackUser}'"); return; } agentClient.Post(new SlackMessage() { Text = $"Your auto bid is {agent.AutoBid}." }); } }
public static void SetAgentAutoBid(string slackUser, int amount, SlackClient agentClient) { lock (ServiceLock) { using (var db = new SlackLeadsBidderContext()) { var agent = db.Agents.FirstOrDefault(e => e.SlackId == slackUser); if (agent == null) { agentClient.PostError($"No agent configured for '{slackUser}'"); return; } agent.AutoBid = amount; db.SaveChanges(); agentClient.PostOk($"You autobid is set to {amount} for next auction."); } } }
public void Autobid(SlackCommandRequest request) { var settings = SlackLeadsBidderSettings.Settings; var agentClient = new SlackClient(request.Response_Url); if (request.Token != settings.SlackCommandAutoBidToken) { agentClient.PostError("Invalid token."); } int amount; if (!int.TryParse(request.Text, out amount) || amount < 0) { SlackLeadsBidderService.GetAgentAutoBid(request.User_Name, agentClient); } else { SlackLeadsBidderService.SetAgentAutoBid(request.User_Name, amount, agentClient); } }