Example #1
0
        public ActionResult UpdateMaterial(int id, MaterialUpdateDto materialUpdateDto)
        {
            var materialModelFromRepo = _repository.GetMaterialById(id);

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

            _mapper.Map(materialUpdateDto, materialModelFromRepo);

            _repository.UpdateMaterial(materialModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateMaterial(int materialId, MaterialUpdateDto materialUpdateDto)
        {
            var material = await _unitOfWork.Material.GetById(materialId);

            if (material != null)
            {
                var result = _mapper.Map(materialUpdateDto, material);
                await _unitOfWork.Material.Update(material);

                await _unitOfWork.Save();

                _logger.LogInformation("PUT api/material/{MaterialId} => OK", materialId);
                return(Ok());
            }
            else
            {
                _logger.LogInformation("PUT api/material/{MaterialId} => NOT OK", materialId);
                return(NoContent());
            }
        }
Example #3
0
        public async Task <IActionResult> UpdateMaterial(int id, [FromBody] MaterialUpdateDto material)
        {
            if (material == null)
            {
                _logger.LogError("Material object sent from client is null");
                return(BadRequest("Material object is null"));
            }
            var materialEntity = await _repository.Material.GetMaterialByIdAsync(id);

            if (materialEntity == null)
            {
                _logger.LogError($"Material with id {id} does not exist");
                return(NotFound());
            }
            _mapper.Map(material, materialEntity);

            _repository.Material.UpdateMaterial(materialEntity);
            await _repository.SaveAsync();

            return(NoContent());
        }