public async Task <ActionResult> PostFolder([FromBody] PostFolderRequest request)
        {
            var newFolder = new Folder
            {
                Name = request.Name
            };

            newFolder.Registers.Add(new Register
            {
                Order         = 0,
                DocumentCount = 0,
                IsActive      = true
            });

            await _documentlibContext.AddAsync(newFolder);

            await _documentlibContext.SaveChangesAsync();

            var folderResponse = new FolderResponse
            {
                Id            = newFolder.Id.ToString(),
                Name          = newFolder.Name,
                Registers     = newFolder.Registers.Select(reg => reg.Id.ToString()).ToArray(),
                DocumentCount = newFolder.Registers.Sum(reg => reg.DocumentCount)
            };

            return(Ok(folderResponse));
        }
Esempio n. 2
0
        public async Task <ActionResult> PutCategory([FromBody] PutCategoryRequest request)
        {
            var newCategory = new Category
            {
                Name         = request.Name,
                Abbreviation = request.Abbreviation
            };
            await _documentlibContext.AddAsync(newCategory);

            await _documentlibContext.SaveChangesAsync();

            return(Ok(newCategory));
        }