public async Task <IActionResult> PutAsync(string code, [FromBody] SupplierForUpdateDto value)
        {
            value.SupplierCode = code;
            await _supplierService.UpdateAsync(value);

            return(Ok());
        }
        public IActionResult UpdateSupplier(int id, [FromBody] SupplierForUpdateDto supplier)
        {
            try
            {
                if (supplier == null)
                {
                    _logger.LogError("Supplier object sent from client is null.");
                    return(BadRequest("Supplier object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid supplier object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                var supplierEntity = _repository.Supplier.GetSupplierById(id);
                if (supplierEntity == null)
                {
                    _logger.LogError($"Supplier with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }

                _mapper.Map(supplier, supplierEntity);

                _repository.Supplier.UpdateSupplier(supplierEntity);
                _repository.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateSupplier action: {ex.InnerException.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Beispiel #3
0
        public IActionResult Update(SupplierForUpdateDto supplierForUpdateDto)
        {
            var result = supplierService.Update(supplierForUpdateDto);

            if (result.Success)
            {
                return(NoContent());
            }
            return(BadRequest(result.Message));
        }
        public IResult Update(SupplierForUpdateDto supplierForUpdateDto)
        {
            var supplier = GetById(supplierForUpdateDto.Id).Data;

            supplier.Description = supplierForUpdateDto.Description;
            supplier.Name        = supplierForUpdateDto.Name;
            supplier.UpdatedAt   = DateTime.Now;

            supplierDal.Update(supplier);
            return(new SuccessResult(Messages.SupplierUpdated));
        }
Beispiel #5
0
        public void Update_WhenUpdatedSupplier_ShouldUpdate()
        {
            // Arrange
            var supplierForUpdateDto = new SupplierForUpdateDto();
            var mockSupplierDal      = new MockSupplierDal().MockUpdate().MockGet(new Supplier());
            var sut = new SupplierManager(mockSupplierDal.Object);

            // Act
            sut.Update(supplierForUpdateDto);

            // Assert
            mockSupplierDal.VerifyUpdate(Times.Once());
        }
        public async Task <IActionResult> UpdateSupplier(int id, SupplierForUpdateDto supplierForUpdateDto)
        {
            var supplierFromRepo = await _repo.GetSupplier(id);

            _mapper.Map(supplierForUpdateDto, supplierFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating supplier {id} failed on save");
        }
Beispiel #7
0
        public static async Task Update(SupplierForUpdateDto supplierForUpdateDto)
        {
            using var client = new HttpClient();
            var uri = $"{APIAddresses.SupplierService}/{supplierForUpdateDto.Id}";

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token);
            var response = await client.PutAsJsonAsync(uri, supplierForUpdateDto);

            if (response.IsSuccessStatusCode)
            {
                return;
            }

            var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result;

            throw new HttpFailureException(errorContent);
        }
Beispiel #8
0
        public void SupplierForUpdateValidator_TrueStory()
        {
            // Arrange
            var model = new SupplierForUpdateDto()
            {
                Id          = 1,
                Description = "Desc Supplier T",
                Name        = "Supplier T"
            };
            var sut = new SupplierForUpdateValidator();

            // Act
            var result = sut.TestValidate(model);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }
Beispiel #9
0
        public async Task UpdateAsync(SupplierForUpdateDto element)
        {
            var supplier = _context.Suppliers.FirstOrDefault(v => v.SupplierCode.Equals(element.SupplierCode));

            if (supplier == null)
            {
                throw new ArgumentException("The given supplier for an update is invalid.");
            }

            var updatedSupplier = new Supplier
            {
                SupplierCode = element.SupplierCode,
                Name         = element.Name ?? supplier.Name,
                Details      = element.Details ?? supplier.Details
            };

            _context.Entry(supplier).CurrentValues.SetValues(updatedSupplier);
            await _context.SaveChangesAsync();
        }