//[Authorize]
        //[Route("api/[controller]/[action]")]
        private async Task <string> GetInspectionHtmlForPdf(int id)
        {
            //await CheckPermission();
            var ir  = new InspectionRepository(_logger);
            var tr  = new TaskRepository(_logger);
            var ur  = new UserRepository(_logger);
            var trr = new TrainRepository(_logger);

            var inspection = await ir.ById(id);

            if (inspection == null)
            {
                return("");
            }
            //throw new Exception("инспекция не найдена");

            inspection.User = await ur.ById(inspection.UserId);

            inspection.Train = await trr.ByIdWithStations(inspection.TrainId);

            var res = await tr.GetInspectionTasksForPdf(id);

            var tasks = res.FirstOrDefault();

            string checkListTypeRussian = null;

            if (inspection.CheckListType == CheckListType.TO1)
            {
                checkListTypeRussian = InspectionRussianName.To1;
            }
            if (inspection.CheckListType == CheckListType.TO2)
            {
                checkListTypeRussian = InspectionRussianName.To2;
            }
            if (inspection.CheckListType == CheckListType.Inspection)
            {
                checkListTypeRussian = InspectionRussianName.PriemkaPoezda;
            }
            if (inspection.CheckListType == CheckListType.Surrender)
            {
                checkListTypeRussian = InspectionRussianName.SdachaPoezda;
            }

            var html = "";/*"@"<html><head>
                           * <style type='text/css'>
                           * .task {
                           * border-collapse: collapse;
                           * border: 1px solid black;
                           * }
                           * .task td {
                           * padding: 5px;
                           * border: 1px solid black;
                           * }
                           * .task th {
                           * padding: 5px;
                           * background-color: #909090;
                           * border: 1px solid black;
                           * }
                           * </style></head><body>";*/

            html += "<table><tr><td>Мероприятие:</td><td>" + checkListTypeRussian + "</td></tr>";
            html += "<tr><td>Поезд:</td><td>" + inspection.Train.Name + "</td></tr>";
            html += "<tr><td>Начато:</td><td>" + inspection.DateStart + "</td></tr>";
            html += "<tr><td>Закончено:</td><td>" + inspection.DateEnd + "</td></tr>";
            html += "<tr><td>Выполнил:</td><td>" + inspection.User.Name + "</td></tr></table>";
            if (tasks != null && tasks.Tasks.Length > 0)
            {
                html +=
                    "<br /><h2>Задачи</h2><table class='task'><tr><th>Вагон</th><th>Местоположение</th><th>Оборудование</th><th>Типовая неисправность</th><th>Описание</th><th>Метка</th><th>№ задачи</th><th>Время</th></tr>";
                foreach (var task in tasks.Tasks)
                {
                    html += "<tr><td>" + task.CarriageSerialNum + "</td><td>" + task.Location + "</td><td>" + task.Equipment + "</td><td>" + task.Fault + "</td><td>" + task.Description + "</td><td>" + task.Label + "</td><td>" + task.Id + "</td><td>" + task.Created + "</td></tr>";
                }
                html += "</table><br /><br />";

                if (tasks.Labels.Any())
                {
                    html += "<h2>Метки</h2><table class='task'><tr><th>Вагон</th><th>Оборудование</th><th>Время</th><th>ИД метки</th></tr>";
                    foreach (var label in tasks.Labels)
                    {
                        html += "<tr><td>" + label.CarriageName + "</td><td>" + label.EquipmentName + "</td><td>" + label.TimeStamp + "</td><td>" + label.LabelSerial + "</td></tr>";
                    }
                    html += "</table><br /><br />";
                }

                if (tasks.Temperatures.Any())
                {
                    html += "<h2>Температура</h2><table class='task'><tr><th>Температура</th><th>Время</th><th>Температура</th><th>Время</th><th>Температура</th><th>Время</th><th>Температура</th><th>Время</th></tr>";
                    var cnt = 0;
                    foreach (var temp in tasks.Temperatures)
                    {
                        if (cnt % 4 == 0)
                        {
                            html += "<tr>";
                        }
                        html += "<td>" + temp.Value + "</td><td>" + temp.TimeStamp + "</td>";
                        if ((cnt + 1) % 4 == 0)
                        {
                            html += "</tr>";
                        }
                        cnt++;
                    }
                    var remain = 4 - (cnt % 4);
                    if (remain > 0)
                    {
                        for (var i = 0; i < remain; i++)
                        {
                            html += "<td></td><td></td>";
                        }
                        html += "</tr>";
                    }
                    html += "</table><br /><br />";
                }
            }
            else
            {
                html += "<h2>Не найдено задач</h2>";
            }

            //html += "</body></html>";
            //
            //var output = _pdfConverter.Convert(new HtmlToPdfDocument
            //{
            //    GlobalSettings = {
            //        ColorMode = ColorMode.Color,
            //        Orientation = Orientation.Portrait,
            //        PaperSize = PaperKind.A4,
            //    },
            //    Objects =
            //    {
            //        new ObjectSettings
            //        {
            //            HtmlContent = html,
            //            WebSettings = { DefaultEncoding = "utf-8" }
            //        }
            //    }
            //});
            ////
            //return File(output, "application/pdf", inspection.Id+"_"+inspection.DateStart+"_"+inspection.CheckListType+".pdf");
            return(html);
        }
        private async Task AddInspectionData(TaskByIdDto result, TaskDetailFromSql item)
        {
            var sqlRInspection = new InspectionRepository(_logger);
            var sqlRUsers      = new UserRepository(_logger);
            var sqlRBrigade    = new BrigadeRepository(_logger);

            var inspection = await sqlRInspection.ById(item.AttributeInspectionId);

            var inspectionUser = await sqlRUsers.ById(inspection.UserId);

            int?inspectionBrigadeType = null;

            if (inspectionUser.BrigadeId.HasValue)
            {
                var inspectionBrigade = await sqlRBrigade.ById(inspectionUser.BrigadeId.Value);

                inspectionBrigadeType = (int)inspectionBrigade.BrigadeType;
            }

            var inspectionToAdd = new InspectionTaskDto
            {
                Id          = inspection.Id,
                DateStart   = inspection.DateStart,
                DateEnd     = inspection.DateEnd,
                User        = inspectionUser.Name,
                Type        = (int)inspection.CheckListType,
                BrigadeType = inspectionBrigadeType,
                Texts       = new List <string>()
            };

            if (item.AttributeCheckListEquipmentId.HasValue)
            {
                var toAddText                = $"{item.EquipmentName} -> {item.CheckListEquipmentTaskName} -> ";
                var checkListStringValue     = string.Empty;
                var taskAttributeStringValue = string.Empty;
                if (item.CheckListEquipmentValueType == 1)
                {
                    if (item.CheckListEquipmentValue == 0)
                    {
                        checkListStringValue = "Нет";
                    }
                    if (item.CheckListEquipmentValue == 1)
                    {
                        checkListStringValue = "Да";
                    }

                    if (item.AttributeValue == 0)
                    {
                        taskAttributeStringValue = "Нет";
                    }
                    if (item.AttributeValue == 1)
                    {
                        taskAttributeStringValue = "да";
                    }
                }
                else
                {
                    checkListStringValue     = item.CheckListEquipmentValue.ToString();
                    taskAttributeStringValue = item.AttributeValue.ToString();
                }

                toAddText += $"{checkListStringValue} -> {taskAttributeStringValue}";

                inspectionToAdd.Texts.Add(toAddText);
            }


            // Для ТО-1 ТО-2 и тд
            if (inspection.CheckListType == CheckListType.TO1 || inspection.CheckListType == CheckListType.TO2)
            {
                //  Уровень критичности → Высокий
                if (item.TaskLevel.HasValue)
                {
                    var toAddText = $"Уровень критичности -> {GetStringTaskLevel(item.TaskLevel.Value)}";
                    inspectionToAdd.Texts.Add(toAddText);
                }

                //Смотрим что добавилось в рамках мероприятия TaskLevel или FaultId, пишим в текст
                if (item.AttributeFaultId.HasValue)
                {
                    var toAddText = $"{item.FaultName} -> {item.EquipmentName}";
                    inspectionToAdd.Texts.Add(toAddText);
                }
            }

            result.Inspections.Add(inspectionToAdd);
        }