public async Task <List <JsonClasses.CorporationHistoryEntry> > WebGenerateCorpHistory(long charId)
        {
            var history = (await APIHelper.ESIAPI.GetCharCorpHistory(Reason, charId))
                          ?.OrderByDescending(a => a.record_id).ToList();

            if (history == null || history.Count == 0)
            {
                return(null);
            }

            JsonClasses.CorporationHistoryEntry last = null;
            foreach (var entry in history)
            {
                var corp = await APIHelper.ESIAPI.GetCorporationData(Reason, entry.corporation_id);

                entry.CorpName  = corp.name;
                entry.IsNpcCorp = corp.creator_id == 1;
                if (last != null)
                {
                    entry.Days = (int)(last.Date - entry.Date).TotalDays;
                }

                entry.CorpTicker = corp.ticker;
                last             = entry;
            }

            var l = history.FirstOrDefault();

            if (l != null)
            {
                l.Days = (int)(DateTime.UtcNow - l.Date).TotalDays;
            }
            return(history.Where(a => a.Days > 0).ToList());
        }
예제 #2
0
        private async Task <string> GenerateCorpHistory(long charId)
        {
            var history = (await APIHelper.ESIAPI.GetCharCorpHistory(Reason, charId))?.OrderByDescending(a => a.record_id).ToList();

            if (history == null || history.Count == 0)
            {
                return(null);
            }

            JsonClasses.CorporationHistoryEntry last = null;
            foreach (var entry in history)
            {
                var corp = await APIHelper.ESIAPI.GetCorporationData(Reason, entry.corporation_id);

                entry.CorpName  = corp.name;
                entry.IsNpcCorp = corp.creator_id == 1;
                if (last != null)
                {
                    entry.Days = (int)(last.Date - entry.Date).TotalDays;
                }

                entry.CorpTicker = corp.ticker;
                last             = entry;
            }

            var l = history.FirstOrDefault();

            if (l != null)
            {
                l.Days = (int)(DateTime.UtcNow - l.Date).TotalDays;
            }

            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("hrmCVCorpName")}</th>");
            sb.AppendLine($"<th scope=\"col-md-auto\">{LM.Get("hrmCVJoined")}</th>");
            sb.AppendLine($"<th scope=\"col\">{LM.Get("hrmCVDays")}</th>");
            sb.AppendLine("</tr>");
            sb.AppendLine("</thead>");
            sb.AppendLine("<tbody>");
            var counter = 1;

            foreach (var entry in history)
            {
                sb.AppendLine("<tr>");
                sb.AppendLine($"  <th scope=\"row\">{counter++}</th>");
                sb.AppendLine($"  <td><a href=\"https://zkillboard.com/corporation/{entry.corporation_id}\">{entry.CorpName}</a>&nbsp;[{entry.CorpTicker}]{(entry.IsNpcCorp ? " (npc)" : null)}{(entry.is_deleted ? " (closed)" : null)}</td>");
                sb.AppendLine($"  <td>{entry.Date.ToShortDateString()}</td>");
                sb.AppendLine($"  <td>{entry.Days}</td>");
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</tbody>");
            return(sb.ToString());
        }