public async Task <List <WebContract> > WebGetCharContracts(long id, string inspectToken)
        {
            var contracts = (await APIHelper.ESIAPI.GetCharacterContracts(Reason, id, inspectToken, null)).Result;

            if (contracts == null)
            {
                return(null);
            }

            var list = new List <WebContract>();

            foreach (var entry in contracts)
            {
                var fromPlace = entry.issuer_id != 0 ? "character" : "corporation";
                var toPlace   = !entry.for_corporation ? "character" : "corporation";
                var fromId    = entry.issuer_id != 0 ? entry.issuer_id : entry.issuer_corporation_id;
                var toId      = entry.acceptor_id;
                var from      = entry.issuer_id != 0
                    ? (await APIHelper.ESIAPI.GetCharacterData(Reason, entry.issuer_id))?.name
                    : (await APIHelper.ESIAPI.GetCorporationData(Reason, entry.issuer_corporation_id))?.name;
                var to = entry.for_corporation
                    ? (await APIHelper.ESIAPI.GetCorporationData(Reason, entry.acceptor_id))?.name
                    : (await APIHelper.ESIAPI.GetCharacterData(Reason, entry.acceptor_id))?.name;

                var ch = await APIHelper.ESIAPI.GetCharacterData(Reason, id);

                var itemList = await ContractNotificationsModule.GetContractItemsString(Reason, entry.for_corporation, ch.corporation_id, id, entry.contract_id, inspectToken);

                list.Add(new WebContract
                {
                    Id            = entry.contract_id,
                    Type          = entry.type,
                    From          = from,
                    To            = to,
                    FromLink      = $"https://zkillboard.com/{fromPlace}/{fromId}/",
                    ToLink        = toId > 0 ? $"https://zkillboard.com/{toPlace}/{toId}/" : "-",
                    Status        = entry.status,
                    CompleteDate  = entry.DateCompleted?.ToString(Settings.Config.ShortTimeFormat) ?? LM.Get("hrmContractInProgress"),
                    Title         = entry.title,
                    IncludedItems = itemList[0],
                    AskingItems   = itemList[1]
                });
            }

            return(list);
        }
Exemplo n.º 2
0
        private async Task <string> GenerateContractsHtml(string token, long inspectCharId, int page)
        {
            var items      = (await APIHelper.ESIAPI.GetCharacterContracts(Reason, inspectCharId, token, null))?.Result.OrderByDescending(a => a.contract_id).ToList();
            var startIndex = (page - 1) * Settings.HRMModule.TableEntriesPerPage;

            items = items.Count == 0 ? items : items.GetRange(startIndex, items.Count > startIndex + Settings.HRMModule.TableEntriesPerPage ? Settings.HRMModule.TableEntriesPerPage : (items.Count - startIndex));
            var sb = new StringBuilder();

            sb.AppendLine("<thead>");
            sb.AppendLine("<tr>");
            sb.AppendLine($"<th scope=\"col-md-auto\">#</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractName")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractType")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractFrom")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractTo")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractStatus")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractDate")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractInfo")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmContractItems")}</th>");
            sb.AppendLine("</tr>");
            sb.AppendLine("</thead>");
            sb.AppendLine("<tbody>");
            var counter = startIndex + 1;

            foreach (var entry in items)
            {
                try
                {
                    var fromPlace = entry.issuer_id != 0 ? "character" : "corporation";
                    var toPlace   = !entry.for_corporation ? "character" : "corporation";
                    var fromId    = entry.issuer_id != 0 ? entry.issuer_id : entry.issuer_corporation_id;
                    var toId      = entry.acceptor_id;
                    var from      = entry.issuer_id != 0
                        ? (await APIHelper.ESIAPI.GetCharacterData(Reason, entry.issuer_id))?.name
                        : (await APIHelper.ESIAPI.GetCorporationData(Reason, entry.issuer_corporation_id))?.name;
                    var to = entry.for_corporation
                        ? (await APIHelper.ESIAPI.GetCorporationData(Reason, entry.acceptor_id))?.name
                        : (await APIHelper.ESIAPI.GetCharacterData(Reason, entry.acceptor_id))?.name;

                    var ch = await APIHelper.ESIAPI.GetCharacterData(Reason, inspectCharId);

                    var itemList = await ContractNotificationsModule.GetContractItemsString(Reason, entry.for_corporation, ch.corporation_id, inspectCharId, entry.contract_id, token);

                    sb.AppendLine($"<tr>");
                    sb.AppendLine($"  <th scope=\"row\">{counter++}</th>");
                    sb.AppendLine($"  <td>Contract</td>");
                    sb.AppendLine($"  <td>{entry.type}</td>");
                    sb.AppendLine($"  <td><a href=\"https://zkillboard.com/{fromPlace}/{fromId}/\">{from}</a></td>");
                    sb.AppendLine(toId > 0 ? $"  <td><a href=\"https://zkillboard.com/{toPlace}/{toId}/\">{to}</a></td>" : "  <td>-</td>");
                    sb.AppendLine($"  <td>{entry.status}</td>");
                    sb.AppendLine($"  <td>{entry.DateCompleted?.ToString(Settings.Config.ShortTimeFormat) ?? LM.Get("hrmContractInProgress")}</td>");
                    sb.AppendLine($"  <td>{entry.title}</td>");
                    if (!string.IsNullOrEmpty(itemList[0]))
                    {
                        sb.AppendLine($"  <td>{LM.Get("contractMsgIncludedItems")}<img src=\"https://github.com/panthernet/ThunderED/blob/master/ThunderED/Content/Icons/itemIconSmall.png?raw=true\" alt=\"\" title=\"{itemList[0]}\"/></td>");
                    }
                    if (!string.IsNullOrEmpty(itemList[1]))
                    {
                        sb.AppendLine($"  <td>{LM.Get("contractMsgAskingItems")}<img src=\"https://github.com/panthernet/ThunderED/blob/master/ThunderED/Content/Icons/itemIconSmall.png?raw=true\" alt=\"\" title=\"{itemList[1]}\"/></td>");
                    }
                    if (string.IsNullOrEmpty(itemList[0]) && string.IsNullOrEmpty(itemList[1]))
                    {
                        sb.AppendLine($"  <td>-</td>");
                    }
                    sb.AppendLine("</tr>");
                }
                catch (Exception ex)
                {
                    await LogHelper.LogEx("", ex, Category);
                }
            }
            sb.AppendLine("</tbody>");
            return(sb.ToString());
        }