Exemplo n.º 1
0
        public Guid Create(int organisationId, int centreId, int categoryId, string studentCode, string studentName, string description, string fileName, byte[] contents)
        {
            var newGuid  = Guid.NewGuid();
            var category =
                PersonnelDataService.RetrieveDocumentTypes(organisationId)
                .FirstOrDefault(e => e.DocumentCategoryId == categoryId);
            var centre            = PersonnelDataService.RetrieveCentre(organisationId, centreId, e => true);
            var basePath          = CreateCentreBase(category.BasePath, centre.Name);
            var categoryFileName  = string.Concat(category.Name, "_", newGuid, "_", fileName);
            var employeeDirectory = GetStudentDirectory(basePath, studentCode) ?? CreateStudentDirectory(basePath, studentName, studentCode);
            var categoryDirectory = Path.Combine(employeeDirectory, category.Name);
            var filePath          = Path.Combine(categoryDirectory, categoryFileName);

            Directory.CreateDirectory(categoryDirectory);
            File.WriteAllBytes(filePath, contents);
            var document = new Entity.Document()
            {
                CentreId        = centreId,
                DocumentTypeId  = categoryId,
                StudentCode     = studentCode,
                CreatedDateTime = DateTime.UtcNow.Date,
                Description     = description,
                FileName        = fileName,
                Location        = filePath,
                StudentName     = studentName,
                Guid            = newGuid
            };

            PersonnelDataService.Create <Entity.Document>(organisationId, document);
            return(newGuid);
        }
Exemplo n.º 2
0
        public Document CreateDocument(int organisationId, int centreId, int documentTypeId, string filePath,
                                       string studentCode, string studentName, string description, string fileName, Guid guid)
        {
            var document = new Document()
            {
                OrganisationId  = organisationId,
                CentreId        = centreId,
                DocumentTypeId  = documentTypeId,
                StudentCode     = studentCode,
                CreatedDateTime = DateTime.UtcNow.Date,
                Description     = description,
                FileName        = fileName,
                Location        = filePath,
                StudentName     = studentName,
                Guid            = guid
            };

            return(_personnelDataService.Create <Document>(organisationId, document));
        }