How to update existing warehouse from code

Member since: 2012


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?

#189010 Mar 08, 2018 14:17
  • Member since: 2012

    Have you tried casting it to Warehouse?

    if (_warehouseRepository.Get(warehouseCode) is Warehouse warehouse)
        warehouse.IsActive = true;

    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.

    #189012 Mar 08, 2018 14:30
  • Member since: 2012

    When casting to Warehouse interface remains null. Although it looked like a valid answer it still remains open to suggestions.

    #189014 Edited, Mar 08, 2018 14:35
  • Member since: 2011

    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

    #189020 Mar 08, 2018 18:06
  • Member since: 2012

    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.

    #189042 Mar 09, 2018 10:01
  • Member since: 2011

    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. 

    #189043 Mar 09, 2018 10:07
  • Member since: 2012

    That's right. Thank you.

    #189044 Mar 09, 2018 10:28
  • Member since: 2012
    var warehouse = new Warehouse(readOnlyWarehouse);


    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? surprised

    #189060 Mar 09, 2018 13:53
  • Member since: 2011

    I didn't write the code. cool

    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 

    #189061 Edited, Mar 09, 2018 13:56
  • Member since: 2012

    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. yell

    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.

    #189062 Mar 09, 2018 14:04
  • Member since: 2011

    Fair enough. I filed a bug report for that - let's see if someone can sneak that bug fix in.

    #189063 Mar 09, 2018 14:25
First   1 2   Last