public HttpResponseMessage Post(AppInfo generateAllFiles)
        {
            Dictionary <string, string> filesDictionary = new Dictionary <string, string>();

            string baseFolder = AppDomain.CurrentDomain.BaseDirectory + "/Download/";

            foreach (ModelInfo tableInfo in generateAllFiles.TableInfomation)
            {
                //if (!tableInfo.Required)
                //    continue;
                // create a folder
                string innerFolder   = tableInfo.TableName + "ServiceTests";
                string currentFolder = baseFolder + innerFolder;
                System.IO.Directory.CreateDirectory(currentFolder);
                GetMicrosoftDatabaseSchemaDetails DbSchema          = new GetMicrosoftDatabaseSchemaDetails();
                List <IModelInfoTemplate>         allLogicTemplates = testsTemplateFactory.GetModelInfoTemplates(tableInfo);

                foreach (IModelInfoTemplate logicTemplate in allLogicTemplates)
                {
                    IModelInfoTemplate template  = allLogicTemplates.FirstOrDefault(c => c.GetClassId() == logicTemplate.GetClassId());
                    string             classText = template.TransformText();
                    // create a file in the folder
                    var    fileName = template.GetClassName() + ".cs";
                    string path     = currentFolder + "/" + fileName;

                    using (FileStream fs = System.IO.File.Create(path))
                    {
                        Byte[] info = new UTF8Encoding(true).GetBytes(classText);
                        // Add some information to the file.
                        fs.Write(info, 0, info.Length);
                    }

                    filesDictionary.Add(path, innerFolder + "/" + fileName);
                }
            }

            string zipFolder = baseFolder + "/Tests.zip";

            if (System.IO.File.Exists(zipFolder))
            {
                System.IO.File.Delete(zipFolder);
            }
            ZipArchive zip = ZipFile.Open(zipFolder, ZipArchiveMode.Create);

            foreach (var file in filesDictionary)
            {
                zip.CreateEntryFromFile(file.Key, file.Value.Replace("_", ""));
            }
            zip.Dispose();

            // return File(zipFolder,"application/zip", "bundle.zip");

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(zipFolder, FileMode.Open, FileAccess.Read);

            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");
            return(result);
        }
        public HttpResponseMessage Post(GenerateFile model)
        {
            ModelInfo modelInfo = model.ModelInfo;
            int       id        = model.TemplateId;

            GetMicrosoftDatabaseSchemaDetails microsoftDatabaseSchemaDetails = new GetMicrosoftDatabaseSchemaDetails();
            List <IModelInfoTemplate>         templates = templateFactory.GetModelInfoTemplates(modelInfo);
            IModelInfoTemplate template = templates.FirstOrDefault(c => c.GetClassId() == id);

            string documentText = "Error no template found!";

            if (template != null)
            {
                documentText = template.TransformText();
            }

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(Encoding.ASCII.GetBytes(documentText))
            };

            result.Content.Headers.ContentDisposition =
                new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = "CertificationCard.cs"
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

            return(result);
        }