User Profile & Activity

Jimmy Tungol Member
Page
of 13
Posted: March 26, 2015 2:53 PM
Thanks Arief. Please keep us posted.
Posted: March 26, 2015 4:06 AM
Have you received the link yet? If so, any thoughts on how this is occuring?
Posted: March 24, 2015 10:00 PM

Email has been sent separately to attach the file via email to keep the confidentiality of the contents.

Posted: March 24, 2015 9:42 PM

Attached are screen captures while running the app with multiple items with the same Display text but different Details.

Posted: March 24, 2015 8:40 PM
Do you accept conferencing? It would be better to just show this while running the app. Cause we are also getting random errors like "Unable to save changes due to an error: An element with the same key already exists in the dictionary." when saving. But will work after the 2nd attempt to save.
This is awesome! We'll give it a try. Thanks!

Okay, considering there is a chance this.Item will not be modified but one of its related entities (e.g. this.Item.Details). In this scenario, the entities.OfType<Item>() will return null. Which means it will not enter the foreach loop, in return any chance of getting the original data from related entities is not possible. You can add the LargeImage and ThumbnailImage properties to this.Item, but these properties are useless if there aren't any changes to the entity fields. Using entities.OfType<Details>() will not return null; however, you can't use this with this.GetSingle(IEntity item) to get the original data, because the method is tied to the parent entity, which is this.Item.

Now, in order to solve this scenario... we have to modify one of Item's fields (e.g. ModifiedDate or something similar) programatically, before DataEditorViewModelBase.ExecuteSave() is called. This workaround tells the framework that something has changed to the Item, eventually adding it to the list of entities where the original data can be retrieved within InitializeSaveRequest.

Hi Arief,

Yes, we've already extended the auto-generated contoller to pick-up files from DbContext on AfterChangesDelegate. But, as I have mentioned... the db.Files property is null, even with implementation of an extended repository (as posted above). As frustating as this can be, we might be dealing with something that has not been fully implemented. If we go back to the original post, the image that we are trying to update is from a related entity (e.g. this.Item.Details.Photo). When capturing the image data from this.Item.Details.ThumbnailImage and this.Item.Details.LargeImage, the properties always return null when it's inside the foreach loop. Another issue, based on related entities, if you only modify the image from the related entity (e.g. this.Item.Details.Photo)... and did not make any changes on this.Item it will never reach the loop because the entities.OfType<Item>() returns null.

Have you tested this type of scenarios? The MyInventory sample, although worth looking into... it is quite basic and the Item entity only contains a flat table implementation, wherein the fields you need is under one table. Except of course, its category. So, if you can provide a sample that deals with complex navigation or related entities, we would very much appreciate it. Although, we can always create a workaround with saving the images using a different controller with the help of RestClient, we're very anxious to see how it should be properly implemented and that if it's actually supported at all.

Many thanks!

Okay, so here's what we did... we extended the auto-generated repository using a partial class and have overriden the InitializeSaveRequest. However, the InitializeSaveRequest method skips the call on foreach loop on save but the data is being saved. Except of course for the image files.

    public class TicketMachineEditViewModel : DataEditorViewModelBase<TicketMachine, ITicketMachineRepository>

Below is the extended repository:

    public partial class TicketMachineRepository
    {
        protected override void InitializeSaveRequest(RestRequest request, IEnumerable<IEntity> entities)
        {
            var p_Items = entities.OfType<TicketMachine>();

            foreach (var p_Item in p_Items)
            {
                var p_OriginalItem = this.GetSingle(p_Item.TicketMachineId);
                var p_Machine = p_OriginalItem.Machine.MachineDetails;

                if (p_Machine.ThumbnailImage != null)
                    request.AddFile("Thumbnail", p_Machine.ThumbnailImage, p_Machine.Photo, "image/jpg");

                if (p_Machine.LargeImage != null)
                    request.AddFile("Large", p_Machine.LargeImage, p_Machine.Photo, "image/jpg");
            }
        }
    }

Please review and see if there's something missing. Both controller and repository files were generated using Intersoft Web API EDM Extensions.

So, you're telling me that the generated repository from the EDMX file is not sufficient? And that the code above is not built in, even with MultiPart enabled? What I want to understand is why I need to extend the repository in this manner with the understanding that this feature is already built in. Please advise if my assumption is wrong and that the code above must be implemented. If your answer is that it should be implemented, please consider the codes posted on the next reply. I have attached a screenshot of the EDMX configuration that you might find interesting.

As always, many thanks!
All times are GMT -5. The time now is 12:02 PM.
Previous Next