コード例 #1
0
        public async Task <IActionResult> CreateCatalog(CatalogToCreateDto model)
        {
            _logger.LogInformation($"{User.Identity.Name}: POST catalogs name:{model.Name}, parentId:{model.ParentId}");

            Catalog catalog = new Catalog()
            {
                Name        = model.Name,
                Description = model.Description,
                ParentId    = model.ParentId
            };

            try
            {
                await _modelBuilderContext.Catalogs.AddAsync(catalog);

                await _modelBuilderContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }


            return(Ok(catalog));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateDocParts(List <DocPart> docParts)
        {
            _logger.LogInformation($"{User.Identity.Name}: PUT docParts");

            _modelBuilderContext.DocParts.UpdateRange(docParts);
            await _modelBuilderContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #3
0
        public async Task <IActionResult> DeleteDoc(Guid docId)
        {
            _logger.LogInformation($"{User.Identity.Name}: DELETE docs/{docId}");

            var doc = await _modelBuilderContext.Docs.FirstOrDefaultAsync(d => d.Id == docId);

            if (doc == null)
            {
                return(NotFound());
            }

            _modelBuilderContext.Docs.Remove(doc);
            await _modelBuilderContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #4
0
        public async Task <IActionResult> EditDocType(DocTypeForUpdateDto model)
        {
            _logger.LogInformation($"{User.Identity.Name}: PUT docTypes id:{model.Id}");

            var docType = await _modelBuilderContext.DocTypes.FindAsync(model.Id);

            if (docType == null)
            {
                return(NotFound());
            }

            docType.Name        = model.Name;
            docType.Description = model.Description;

            _modelBuilderContext.Update(docType);
            await _modelBuilderContext.SaveChangesAsync();

            return(Ok(docType));
        }