Have you tried casting it to Warehouse?
if (_warehouseRepository.Get(warehouseCode) is Warehouse warehouse) { warehouse.IsActive = true; _warehouseRepository.Save(warehouse); }
I haven't actually tried it and it is a bit ugly but as the Get function only returns IWarehouse you can't make changes to it.
When casting to Warehouse interface remains null. Although it looked like a valid answer it still remains open to suggestions.
I'm commuting now so can't check to be sure, but you can do like this:
var warehouse = new Warehouse(readOnlyWarehouse);
Then just update the warehouse and save it with IWarehouseRepository
I have tried that but on stepping over the actual save method VS hangs for a bit only to show me pop-up with the following message:
The debugger attempted to call a functin within the debugged process but this function call is being aborted.
I can confirm that code above is indeed correct.
The error you see is a problem with the debugger in VS and has nothing to do with the API.
Wait..what?
new Warehouse(copyFrom: loadedWarehouse) won't give you a new warehouse with new/blank identifiers and the rest is copied?
It will copy everything including identifiers to get an existing entity that can be modified, not really what you would expect from a constructor or is it?
I didn't write the code.
Well, it would be better if it implemented IReadonly, but we have to live with what we have today.
I'm not saying no to improvements,but in the end it always comes to priorty
All change comes to priorities.
I still think someone actually looking for creating a new Warehouse by copying an existing one is in for a very rude surprise.
You might want to mention the constructor here:
Only example for saving a Warehouse there creates a new one with the empty constructor. It doesn't give any pointers for this modify an existing solution.
Fair enough. I filed a bug report for that - let's see if someone can sneak that bug fix in.
I updated the documentation as well - someone from Doc team (probably Bob) will review and publish it.
It is broken. Expanding the code example link below:
Use IWarehouseRepository.Save(IWarehouse) to edit and save a warehouse.
Note: The IWarehouse object returned from Get and List methods above IWarehouseRepository is read-only. So, to edit it, you must make a writable clone object then update it, as is.
Actually expands the code example below:
Use IWarehouseRepository.Save(IWarehouse) to add a warehouse.
Looks like a classic copy-paste miss.
Good spot :). But it's not a copy-paste error, editing a document with code can be quite, tricky. I will need the superior editing skill from Bob to make it right.
Btw the bug I reported is now under review - my boss has fixed it. Take note @Erik, you don't get that a lot ;)
Hopefully, the editing has now been fixed on this page -- Let us know Erik.
@Quan Duly noted. Is it a breaking changes so it will come in commerce 13 or did he sneak it into 12?
@Bob works as it should. Thanks Bob. :)
Hi,
is there any way of updating fields like IsActive, IsFullfilmentCenter and so on from code? Or address details?
I am using Get(string code) on instance of IWarehouseRepository.
After checking if the warehouse was not null I cannot set any of the values. Is there some kind of substitue for writable clone that is present in CMS?