public async Task <CommandResult> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var order = await _ordersRepository.GetById(request.Id);

                var item = await _itemsRepository.GetById(order.ItemId);

                order.Cancel(item);
                await _warehouseDbContext.SaveChangesAsync();

                await _warrantyService.DeleteWarranty(order.OrderItemUid);

                return(new CommandResult
                {
                    IsCompleted = true
                });
            }
            catch (Exception ex)
            {
                return(new CommandResult
                {
                    IsCompleted = false,
                    Reason = ex.Message
                });
            }
        }
示例#2
0
        public void DeleteSeededWarranty(Guid warrantyId)
        {
            var item = Warranty.GetWarranty(warrantyId);

            Warranty.DeleteWarranty(item.WarrantyId);

            DeleteSeededTeam(item.TeamId);
            DeleteSeededUser(item.UserId);
        }
        public void AddRemoveWarrantyTest()
        {
            var teamDto = SeedTeam();
            var userDto = SeedUser();

            WarrantyDto dto = new WarrantyDto()
            {
                WarrantyId          = Guid.NewGuid(),
                TeamId              = teamDto.TeamId,
                UserId              = userDto.UserId,
                WarrantyName        = TEST_WARRANTY_NAME,
                WarrentyDescription = TEST_WARRANT_DESC
            };

            var addResult = Service.AddWarranty(dto);

            Assert.IsTrue(addResult.IsSuccess);

            var warranty = Service.GetWarranty(dto.WarrantyId);

            Assert.IsNotNull(warranty);
            Assert.AreEqual(dto.WarrantyId, warranty.WarrantyId);
            Assert.AreEqual(dto.WarrantyName, warranty.WarrantyName);
            Assert.AreEqual(dto.WarrentyDescription, warranty.WarrentyDescription);

            dto.WarrentyDescription = TEST_WARRANT_DESC_2;
            var updateResult = Service.UpdateWarranty(dto);

            Assert.IsTrue(updateResult.IsSuccess);

            warranty = Service.GetWarranty(dto.WarrantyId);
            Assert.IsNotNull(warranty);
            Assert.AreEqual(TEST_WARRANT_DESC_2, warranty.WarrentyDescription);

            var deleteResult = Service.DeleteWarranty(dto.WarrantyId);

            Assert.IsTrue(deleteResult.IsSuccess);

            DeleteSeededTeam(teamDto.TeamId);
            DeleteSeededUser(userDto.UserId);
        }