public void ChangeTemplateData(int templateId, WordTemplateDO template) { GvaWordTemplate templateData = this.unitOfWork.DbContext.Set<GvaWordTemplate>() .Where(t => t.GvaWordTemplateId == templateId) .Single(); templateData.DataGeneratorCode = template.DataGenerator.Code; templateData.Description = template.Description; templateData.Name = template.Name; if (template.TemplateFile != null) { using (MemoryStream stream = new MemoryStream()) using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString)) { connection.Open(); using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", template.TemplateFile.Key)) { blobStream.CopyTo(stream); templateData.Template = stream.ToArray(); } } } this.unitOfWork.Save(); }
public void CreateNewTemplate(WordTemplateDO template) { GvaWordTemplate newTemplate = new GvaWordTemplate() { Name = template.Name, Description = template.Description, DataGeneratorCode = template.DataGenerator.Code }; using (MemoryStream stream = new MemoryStream()) using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString)) { connection.Open(); using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", template.TemplateFile.Key)) { blobStream.CopyTo(stream); newTemplate.Template = stream.ToArray(); } } this.unitOfWork.DbContext.Set<GvaWordTemplate>().Add(newTemplate); this.unitOfWork.Save(); }
public IHttpActionResult PostTemplate(int templateId, WordTemplateDO template) { using (var transaction = this.unitOfWork.BeginTransaction()) { this.wordTemplateRepository.ChangeTemplateData(templateId, template); transaction.Commit(); return Ok(); } }
public IHttpActionResult PostNewTemplate(WordTemplateDO template) { using (var transaction = this.unitOfWork.BeginTransaction()) { this.wordTemplateRepository.CreateNewTemplate(template); transaction.Commit(); return Ok(); } }