Ejemplo n.º 1
0
        public IActionResult UpdateItem(Item updatedItem)
        {
            // Prepare required data
            var updateTime = DateTime.Now;

            // This is the func for getting the data
            ItemResult g(int i) => _stateService.GetItemById(i);

            // This is the func for saving the data
            ItemResult s(Item i) => _stateService.UpdateItem(i);

            return
                // Validate the incoming state
                (ItemFunctions.ValidateItem(updatedItem)
                 // Create and execute the command based
                 .IfSuccess(_ => ItemCommandExecutors.Execute(
                                new UpdateItemCommand(
                                    () => g(updatedItem.Id), s,
                                    updatedItem.Data,
                                    updatedItem.ModifiedAt)))
                 // Handle the result of the command
                 .IfSuccess(updatedItem => _stateService.UpdateItem(updatedItem))
                 // Return the appropriate response
                 .Into(ToResponse));
        }
Ejemplo n.º 2
0
        public IActionResult CreateItem(Item item)
        {
            var creationTime = DateTime.Now;

            return
                // Make sure the updateItem is valid
                (ItemFunctions.ValidateItem(item, creationTime)
                 // Save the state
                 .IfSuccess(item => _stateService.CreateItem(item))
                 // Return the appropriate response
                 .Into(item => ToResponse(item, 201)));
        }