public async Task <IActionResult> UpdateSale([FromBody] SaleDTO sale)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (sale.Id <= 0)
            {
                return(BadRequest(sale.Id));
            }

            var updateSaleCommand = new UpdateSaleCommand {
                Model = sale
            };

            try
            {
                await _mediator.Send(updateSaleCommand);
            }
            catch (Exception)
            {
                _logger.LogWarning($"{sale.Id} {SalesConstants.UPDATE_SALE_CONFLICT}");
                return(Conflict());
            }

            _logger.LogInformation($"{sale.Id} {SalesConstants.UPDATE_SALE_SUCCESS}");
            return(Ok(sale));
        }
        public async Task Handler_GivenValidData_ShouldUpdateSale()
        {
            // Arrange
            var sale = new SaleDTO
            {
                Id     = 2,
                Date   = new DateTime(2019, 01, 01),
                Amount = 600,
            };

            var command = new UpdateSaleCommand {
                Model = sale
            };

            // Act
            var handler = new UpdateSaleCommand.UpdateSaleCommandHandler(Context);
            await handler.Handle(command, CancellationToken.None);

            var entity = Context.Sales.Find(sale.Id);

            // Assert
            entity.ShouldNotBeNull();

            entity.Date.ShouldBe(command.Model.Date);
            entity.Amount.ShouldBe(command.Model.Amount);
        }
Esempio n. 3
0
 public UpdateSaleCommandHandlerTest()
 {
     request = new UpdateSaleCommand(new SaleResource()
     {
         CityName    = "Update",
         Price       = 120,
         ProductId   = "1",
         ProductName = "Update",
         UserName    = "******",
         Id          = 2
     });
 }
        public async Task Handle_GivenInvalidSaleData_ThrowsException()
        {
            // Arrange
            var sale = new SaleDTO
            {
                Id     = 99,
                Date   = new DateTime(2019, 01, 01),
                Amount = 200,
            };

            var command = new UpdateSaleCommand {
                Model = sale
            };

            // Act
            var handler = new UpdateSaleCommand.UpdateSaleCommandHandler(Context);

            // Assert
            await Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None));
        }
Esempio n. 5
0
 public Task UpdateSale(UpdateSaleCommand command, CancellationToken token)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
        //PUT : /api/Users/Update
        public async Task <ActionResult <IEnumerable <object> > > Update([FromBody] UpdateSaleRequestModel request)
        {
            var update = new UpdateSaleCommand(_context);

            return(Ok(await Task.Run(() => update.UpdateSale(request))));
        }
Esempio n. 7
0
 public Task <Response <SaleDetailApiModel> > Handle(UpdateSaleCommand request, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }