public void AddLoan(DiscordMember member, DiscordGuild guild, int totalAmount, int interestAmount) { var loanCtx = MultiBotDb.Loans; try { int orgId = new OrgController().GetOrgId(guild); var loan = new Loans() { LoanId = GetHighestLoanId() + 1, ApplicantId = new MemberController().GetMemberbyDcId(member, guild).UserId, RequestedAmount = totalAmount, RemainingAmount = totalAmount + interestAmount, InterestAmount = interestAmount, Status = "Waiting To Be Funded", OrgId = orgId }; loanCtx.Add(loan); MultiBotDb.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } }
public Mcmember GetMember(string name, DiscordGuild guild) { var orgId = new OrgController().GetOrgId(guild); var memberCtx = MultiBotDb.Mcmember; return(memberCtx.SingleOrDefault(x => x.Username == name && x.OrgId == orgId)); }
public Mcmember GetMemberbyDcId(DiscordMember member, DiscordGuild guild) { var orgId = new OrgController().GetOrgId(guild); var memberCtx = MultiBotDb.Mcmember; if (memberCtx.Any(x => x.DiscordId == member.Id.ToString())) { return(memberCtx.Single(x => x.DiscordId == member.Id.ToString() && x.OrgId == orgId)); } else { AddMember(new Ranks().GetNickWithoutRank(member.Nickname), orgId, member); return(memberCtx.Single(x => x.DiscordId == member.Id.ToString() && x.OrgId == orgId)); } }
public void WipeTransactions(DiscordGuild guild) { var transContext = MultiBotDb.Transactions; OrgController orgC = new OrgController(); var memCont = new MemberController(); var bankItems = transContext.ToList(); var users = memCont.GetMembersByOrgId(orgC.GetOrgId(guild)); foreach (var user in users) { bankItems.Single(x => x.UserId == user.UserId).Amount = 0; } transContext.UpdateRange(bankItems); MultiBotDb.SaveChanges(); }
public DiscordEmbed GetLoanEmbed(DiscordGuild guild) { try { var loanCtx = MultiBotDb.Loans; int orgId = new OrgController().GetOrgId(guild); var loanList = loanCtx.AsQueryable().AsQueryable().Where(x => x.OrgId == orgId && x.IsCompleted == 0).ToList(); var memberController = new MemberController(); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.Title = $"{guild.Name} Loans"; builder.Timestamp = DateTime.Now; builder.Description = $"Here is a list of all of your Loans that are outstanding or waiting for funding! \n\u200b"; builder.AddField("Status: Not Funded", "Waiting To Be Funded").WithColor(DiscordColor.Green); foreach (var item in loanList.AsQueryable().Where(x => x.Status == "Waiting To Be Funded")) { builder.AddField($"Loan ID: {item.LoanId} \nApplicant: {memberController.GetMemberById(item.ApplicantId).Username}", $"Asking for ${FormatHelpers.FormattedNumber(item.RequestedAmount.ToString())} for interest payment of " + $"${FormatHelpers.FormattedNumber(item.InterestAmount.ToString())}") .WithColor(DiscordColor.Green); } builder.AddField("\u200b\n Status: Funded", "Awaiting Repayment").WithColor(DiscordColor.Green); foreach (var item in loanList.AsQueryable().Where(x => x.Status == "Funded")) { builder.AddField($"Loan ID: {item.LoanId} \nApplicant: {memberController.GetMemberById(item.ApplicantId).Username}" + $"\nFunded by {memberController.GetMemberById(item.FunderId.GetValueOrDefault()).Username}", $"Total Loan: ${FormatHelpers.FormattedNumber((item.RequestedAmount + item.InterestAmount).ToString())} \n" + $"Remaining Amount: ${FormatHelpers.FormattedNumber(item.RemainingAmount.ToString())}") .WithColor(DiscordColor.Red); } return(builder.Build()); } catch (Exception e) { tHelper.LogException($"Method: GetLoanEmbed; Org: {guild.Name};", e); Console.WriteLine(e); return(null); } }
public DiscordEmbed GetTopXp(DiscordGuild guild) { var orgId = new OrgController().GetOrgId(guild); var memberByXP = MultiBotDb.Mcmember.Where(x => x.OrgId == orgId).OrderBy(x => x.Xp).ToList(); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.Title = $"{guild.Name} Top XP Earners"; for (int i = 0; i < 10; i++) { builder.AddField(memberByXP[i].Username, $"Current Experience Points: {memberByXP[i].Xp}"); } builder.WithFooter("You can gain experience by completing dispatches, recruiting, participating in commerce events or depositing credits or merits to the bank"); return(builder.Build()); }
public bool Enlist(CommandContext ctx, string type) { var org = new OrgController().GetOrgId(ctx.Guild); DispatchType dType = null; try { switch (type) { case "medical": dType = this.GetDispatchType(type); var newsub = new OrgDispatch(); newsub.OrgId = org; newsub.DispatchType = dType.DispatchTypeId; MultiBotDb.OrgDispatch.Add(newsub); MultiBotDb.SaveChanges(); break; default: ctx.RespondAsync("Enlistment types include: 'medical', please try again"); break; } var en = new MultiBotDb().OrgDispatch.FirstOrDefault(x => x.OrgId == org && x.DispatchType == dType.DispatchTypeId); if (en != null) { ctx.RespondAsync("You have been successfully subscribed to 'medical'"); return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); ctx.RespondAsync("something went wrong"); return(false); } }
public Mcmember GetMemberbyDcId(DiscordMember member, DiscordGuild guild) { var orgId = new OrgController().GetOrgId(guild); var memberCtx = MultiBotDb.Mcmember; if (memberCtx.Any(x => x.DiscordId == member.Id.ToString() && x.OrgId == orgId)) { return(memberCtx.Single(x => x.DiscordId == member.Id.ToString() && x.OrgId == orgId)); } else { if (member.Nickname != null) { AddMember(member.Nickname, orgId, member); } else { AddMember(member.DisplayName, orgId, member); } return(memberCtx.Single(x => x.DiscordId == member.Id.ToString() && x.OrgId == orgId)); } }
public async Task AddWorkOrder(CommandContext ctx, string title, string description, string type, string location, List <Tuple <string, int> > reqs) { var id = new OrgController().GetOrgId(ctx.Guild); try { var order = new WorkOrders() { Id = GetHighestWorkOrder(id) + 1, Name = $"{title}- requested by {ctx.Member.Nickname ?? ctx.Member.DisplayName}", Description = description, Location = location, WorkOrderTypeId = (await GetWorkOrderType(ctx, type)).Id, OrgId = id, isCompleted = false }; MultiBotDb.WorkOrders.Add(order); MultiBotDb.SaveChanges(); foreach (var item in reqs) { var orderReqs = new WorkOrderRequirements(); orderReqs.Material = item.Item1; orderReqs.Amount = item.Item2; orderReqs.WorkOrderId = order.Id; orderReqs.TypeId = order.WorkOrderTypeId; MultiBotDb.WorkOrderRequirements.Add(orderReqs); MultiBotDb.SaveChanges(); } } catch (Exception e) { tHelper.LogException($"Method: AddWorkOrder; Org: {ctx.Guild.Name}; Message: {ctx.Message}; User:{ctx.Member.Nickname}", e); Console.WriteLine(e); } }
public async Task AddWorkOrder(CommandContext ctx, string name, string description, string type, string location, List <Tuple <string, int> > reqs) { var id = new OrgController().GetOrgId(ctx.Guild); try { var order = new WorkOrders() { Id = GetHighestWorkOrder(id) + 1, Name = name, Description = description, Location = location, WorkOrderTypeId = (await GetWorkOrderType(ctx, type)).Id, OrgId = id, isCompleted = false }; MultiBotDb.WorkOrders.Add(order); MultiBotDb.SaveChanges(); foreach (var item in reqs) { var orderReqs = new WorkOrderRequirements(); orderReqs.Material = item.Item1; orderReqs.Amount = item.Item2; orderReqs.WorkOrderId = order.Id; orderReqs.TypeId = order.WorkOrderTypeId; MultiBotDb.WorkOrderRequirements.Add(orderReqs); MultiBotDb.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); } }