Пример #1
0
        public async Task <bool> SaveAssignmentDocumentToFile(AssignmentDocumentUploadViewModel model)
        {
            string path = await _documentIOService.SaveAssignmentDocumentAsync(model.FormFile, model.ActivityId);

            if (path.Equals(string.Empty))
            {
                return(false);
            }

            var document = CreateDocument(model.FormFile, model.UserId, path);

            if (!await SaveDocument(document))
            {
                return(false);
            }

            var documentId = await _context.Documents.Where(d => d.Path.Equals(path)).Select(d => d.Id).FirstOrDefaultAsync();

            DocumentsAssignments documentsAssignment = new DocumentsAssignments
            {
                ActivityId = model.ActivityId,
                DocumentId = documentId
            };

            return(await SaveDocumentAssignment(documentsAssignment));
        }
Пример #2
0
        private bool RemoveAssignmentDocument(Document document, DocumentsAssignments documentAssignment)
        {
            var success = _documentIOService.RemoveDocument(document.Path);

            if (success)
            {
                _context.DocumentsAssignments.Remove(documentAssignment);
                _context.Documents.Remove(document);
                return(true);
            }
            return(false);
        }
Пример #3
0
 private async Task <bool> SaveDocumentAssignment(DocumentsAssignments documentsAssignment)
 {
     _context.DocumentsAssignments.Add(documentsAssignment);
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateException due)
     {
         LogException(due);
         return(false);
     }
     return(true);
 }