public async Task <Guid> Add(Document document)
        {
            _context.Documents.Add(document);
            await _context.SaveChangesAsync();

            return(document.Id);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutDocument(int id, Document document)
        {
            if (id != document.Id)
            {
                return(BadRequest());
            }

            _context.Entry(document).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DocumentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        // TODO: Document Order can be separated in different model. So no need to send whole documents.
        public async Task <IEnumerable <Document> > ReOrderDocumentsAsync(IEnumerable <Document> documents)
        {
            // TODO: Reorder codd here.

            await _documentContext.SaveChangesAsync();

            return(_documentContext.Documents);
        }
Ejemplo n.º 4
0
        public async Task <bool> Add(User user)
        {
            _context.Users.Add(user);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Ejemplo n.º 5
0
 public async Task CompleteAsync()
 {
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 6
0
        public async Task <bool> DeleteDocument(int id)
        {
            var document = await _context.Documents
                           .Where(d => d.Id == id)
                           .FirstOrDefaultAsync();

            if (document != null)
            {
                var location = document.Location;
                File.Delete(location);
            }
            else
            {
                return(false);
            }

            _context.Documents.Remove(document);

            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> DeleteFileAsync(string filename)
        {
            try
            {
                Document document = _context.Documents.Where(x => x.Name == filename).FirstOrDefault <Document>();
                if (document != null)
                {
                    _context.Documents.Attach(document);
                }
                _context.Documents.Remove(document);
                await _context.SaveChangesAsync();


                return(Ok("File deleted"));
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);          //logging
                return(NotFound("File not found")); // returns a NotFoundResult with Status404NotFound response.
            }
        }
Ejemplo n.º 8
0
        public async Task Record(string client, string documentId, IEnumerable <string> keywords)
        {
            if (string.IsNullOrWhiteSpace(client) || string.IsNullOrWhiteSpace(documentId) || keywords == null)
            {
                _logger.LogWarning($"Invalid input, keywords not persisted for client {client}, documentId {documentId}");
                return;
            }

            var documentItem = new DocumentItem
            {
                Client     = client,
                DocumentId = documentId,
                Keywords   = string.Join(',', keywords)
            };

            await _context.DocumentItems.AddAsync(documentItem);

            await _context.SaveChangesAsync();

            _logger.LogInformation($"Successfully persisted result for client: {client}, document: {documentId}");
        }
        public async Task Add(Document document, CancellationToken cancellationToken)
        {
            await context.AddAsync(document, cancellationToken);

            await context.SaveChangesAsync(cancellationToken);
        }
Ejemplo n.º 10
0
 public Task Save() => _context.SaveChangesAsync();