Exemplo n.º 1
0
        public async Task <ActionResult> PutFolder([FromBody] PutFolderRequest request)
        {
            var folder = await _documentlibContext.Folders.FindAsync(request.Id);

            folder.Name = request.Name;

            _documentlibContext.Update(folder);
            await _documentlibContext.SaveChangesAsync();

            var response = new FolderResponse
            {
                Id            = folder.Id.ToString(),
                Name          = folder.Name,
                Registers     = folder.Registers?.Select(reg => reg.Id.ToString()).ToArray() ?? new string[0],
                DocumentCount = folder.Registers?.Sum(reg => reg.DocumentCount) ?? 0
            };

            return(Ok(response));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> UpdateCategory([FromBody] PostCategoryRequest request)
        {
            var category = _documentlibContext.Categories.Single(cat => cat.Id == request.Id);

            category.Name         = request.Name;
            category.Abbreviation = request.Abbreviation;

            _documentlibContext.Update(category);
            await _documentlibContext.SaveChangesAsync();

            return(Ok(category));
        }
Exemplo n.º 3
0
        public async Task <LibDocument> UpdateDocumentAsync(Guid docId, string name, Guid categoryId, Guid folderId, DateTimeOffset date, string[] tags)
        {
            var category = _documentlibContext.Categories.SingleOrDefault(cat => cat.Id == categoryId);

            var document = await _documentlibContext.LibDocuments
                           .Include(doc => doc.Category)
                           .Include(doc => doc.Register)
                           .ThenInclude(reg => reg.Folder)
                           .Include(doc => doc.Register)
                           .ThenInclude(reg => reg.Documents)
                           .Include(doc => doc.Tags)
                           .ThenInclude(tag => tag.Tag)
                           .SingleOrDefaultAsync(doc => doc.Id == docId);

            document.Name     = name;
            document.Category = category;

            if (document.Register.Folder.Id != folderId)
            {
                var folder = _documentlibContext.Folders
                             .Include(f => f.Registers)
                             .Single(f => f.Id == folderId);

                var register = GetNextRegister(folder);

                register.DocumentCount++;
                document.Register.DocumentCount--;
                _documentlibContext.Update(document.Register);
                document.Register = register;
            }
            await AddTagsAsync(tags, document);

            _documentlibContext.Update(document);
            await _documentlibContext.SaveChangesAsync();

            return(document);
        }