Пример #1
0
        public IActionResult CreatePDF([FromQuery] int?[] ids)
        {
            var response = new ListResponse <ShapesDTO>();

            try
            {
                IEnumerable <ShapesDTO> result = null;
                result = ids.Length > 0 ? _shapesLogic.GetShapesByIds(ids.Cast <int>().ToArray()) : _shapesLogic.GetAllShapes();

                var fileList    = new List <string>();
                var zipFileName = Path.Combine(Directory.GetCurrentDirectory(),
                                               @"PDF\" + DateTime.Now.ToFileTime() + ".zip");
                if (result.Count() == 0)
                {
                    response.Messages = ResponseMessages.NotFound();
                    return(NotFound(response));
                }

                foreach (var shapesDto in result)
                {
                    var fileName = Path.Combine(Directory.GetCurrentDirectory(),
                                                @"PDF\" + DateTime.Now.ToFileTime() + ".pdf");
                    CreatePDFFileWithZip(shapesDto, fileName);
                    fileList.Add(fileName);
                }

                CreateZipFile(zipFileName, fileList);
                response.Messages = ResponseMessages.CreatedPDF("File has been created at this URL = " + zipFileName);
                response.Model    = result.ToList();
                return(Ok(response));
            }
            catch (Exception exception)
            {
                response.Messages = ResponseMessages.InternalServerError(exception.ToString());
                return(StatusCode(500, response));
            }
        }