Example #1
0
        public async Task <ICommandResult> HandleAsync(UpdateBookMarksCommand command)
        {
            command.Validate();

            if (!command.IsValid)
            {
                return(new CommandResult(false, command.Errors));
            }

            var product = await _productRepository.GetAsync(command.ProductId);

            if (product is null)
            {
                return(new CommandResult(false, "Product not found"));
            }

            if (product.ProductBookMarks is null || !product.ProductBookMarks.Any())
            {
                product.ClearProductBookMarks();
            }

            foreach (var item in command.BookMarks)
            {
                product.AddProductBookMarks(item.Code, item.Name, item.Value, item.Count);
            }

            await _productRepository.UpdateProductBookMarkAsync(product.ProductBookMarks);

            return(new CommandResult(true, "Product Bookmarks successfully updated."));
        }
Example #2
0
        public async Task <IActionResult> UpdateProductBookMarkAsync(string id, UpdateBookMarksCommand updateCommand)
        {
            if (string.IsNullOrEmpty(updateCommand.ProductId))
            {
                updateCommand.ProductId = id;
            }

            var result = await _updateBookMarksHandler.HandleAsync(updateCommand);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(Ok());
        }
Example #3
0
 public ICommandResult Handle(UpdateBookMarksCommand command)
 {
     throw new NotImplementedException();
 }