/// <summary>
        /// Создать DTO из сущности
        /// </summary>
        public static CaseFolderListItemDto MapFromCaseEntity(Domain.Entities.CaseFolder caseFolder)
        {
            if (caseFolder == null)
            {
                return(null);
            }

            var dto = new CaseFolderListItemDto
            {
                Id    = caseFolder.Id,
                Cases = new List <CaseListItemDto>()
            };

            var    caseFolderData = JsonConvert.DeserializeObject <List <CaseFolderDataDto> >(caseFolder.Data);
            string address        = null;
            string applicant      = null;
            string victim         = null;

            if (caseFolderData != null && caseFolderData.Any())
            {
                var addressItems = new List <string>
                {
                    caseFolderData.FirstOrDefault(c => c.FieldId == ObjectFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == MunicipalityFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == LocalityFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == StreetFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == HomeFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == HousingFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == PorchFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == FloorFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == ApartmentFieldId)?.Value,
                    caseFolderData.FirstOrDefault(c => c.FieldId == CodeFieldId)?.Value
                };

                address   = string.Join(", ", addressItems.Where(a => !string.IsNullOrEmpty(a)));
                applicant = caseFolderData.FirstOrDefault(c => c.FieldId == ApplicantFieldId)?.Value;
                victim    = caseFolderData.FirstOrDefault(c => c.FieldId == VictimFieldId)?.Value;
            }

            var orderedCases = caseFolder.Cases.OrderByDescending(x => x.Created).ToList();

            foreach (var caseItem in orderedCases)
            {
                dto.Cases.Add(CaseListItemDto.MapFromCaseEntity(caseItem, address, applicant, victim));
            }

            var firstCasesCreated = orderedCases.FirstOrDefault();

            if (firstCasesCreated != null)
            {
                dto.CreatedDate = firstCasesCreated.Created;
            }

            return(dto);
        }
        /// <summary>
        /// Создать DTO из сущности
        /// </summary>
        public static CaseListItemDto MapFromCaseEntity(Domain.Entities.Case entity, string address, string applicant, string victim)
        {
            if (entity == null)
            {
                return(null);
            }

            var dto = new CaseListItemDto
            {
                Id           = entity.Id,
                CaseFolderId = entity.CaseFolder.Id,
                CreatedDate  = entity.Created,
                Address      = address,
                Applicant    = applicant,
                Victim       = victim,
                Index        = entity.IndexValue,
                State        = entity.Status,
                TypeTitle    = entity.Type.GetTitle(),
                TypeId       = entity.Type.Id
            };

            return(dto);
        }