Esempio n. 1
0
        public NoteFileContent AddFile(string userId, FileWithContent file, string path)
        {
            string name = $"{userId}_" +
                          $"{DateTime.UtcNow:yyyy-MM-dd_h-mm-ss_tt}" +
                          $".{file.File.FileName.Split('.').Last()}";

            Console.WriteLine(name);
            try
            {
                path = GetFilePath(path, file.File.FileType);
            }
            catch (Exception)
            {
                throw new Exception("Incorrect file type.\n");
            }

            DirectoryInfo dirInfo = new DirectoryInfo(path);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            File.WriteAllBytes($"{path}/{name}", file.Content);

            file.File.FileName = name;
            return(_noteRepository.AddFile(Guid.Parse(userId), file.File));
        }
Esempio n. 2
0
 public IActionResult AddFile(string userId, [FromBody] FileWithContent file)
 {
     try
     {
         Console.WriteLine(file.Content);
         return(Ok(_facade.AddFile(userId, file, Path)));
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
Esempio n. 3
0
        public void CreateDiplomaSupplementReportFunctionTest_ShouldBeSuccess()
        {
            var student = new StudentExtendedProxy {
                FirstName = "firstName"
            };
            var fileWithContent = new FileWithContent("TestName", null);

            A.CallTo(() => reportsCreator.CreateDiplomaSupplement(student)).Returns(fileWithContent);

            RunServer(new CreateDiplomaSupplementReportFunction(DatabaseAuthorizer, reportsCreator));
            var receivedFileWithContent = SendRequest <FileWithContent>("CreateDiplomaSupplementReport", GetDefaultParameters(), student.ToJson());

            A.CallTo(() => reportsCreator.CreateDiplomaSupplement(student)).MustHaveHappened(Repeated.Exactly.Once);
            Assert.That(receivedFileWithContent.FileName, Is.EqualTo(fileWithContent.FileName));
        }
Esempio n. 4
0
        public FileWithContent Execute(StudentBasedProxy student)
        {
            var fullTemplateName = Path.Combine(folderWithTemplates, TemplateName);

            File.Copy(fullTemplateName, tempDocumentName, true);

            var studentExtended = databaseStudentReader.GetExtendedProxy(student);
            var disciplines     = databaseDisciplineReader.GetDisciplinesWithUsingFilters(null, null, studentExtended.GroupName)
                                  .Select(databaseDisciplineReader.GetExtendedProxy).ToArray();
            var group = databaseGroupReader.GetGroupsWithUsingFilters(studentExtended.GroupName)
                        .Select(databaseGroupReader.GetExtendedProxy).First();

            using (var outputDocument = new TemplateProcessor(tempDocumentName).SetRemoveContentControls(true)) {
                outputDocument.FillContent(CreateContent(studentExtended, disciplines, group));
                outputDocument.SaveChanges();
            }

            var fileWithContent = new FileWithContent(TemplateName, File.ReadAllBytes(tempDocumentName));

            File.Delete(tempDocumentName);
            return(fileWithContent);
        }