Пример #1
0
        public async Task <IActionResult> EditCatalog(CatalogForUpdateDto model)
        {
            _logger.LogInformation($"{User.Identity.Name}: PUT catalogs id:{model.Id}");

            var catalog = await _modelBuilderContext.Catalogs.FirstOrDefaultAsync(c => c.Id == model.Id);

            if (catalog == null)
            {
                return(BadRequest("Каталог не найден."));
            }

            catalog.Description = model.Description;

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


            return(Ok(catalog));
        }
Пример #2
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));
        }