Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot save an entity when fireEvents is set to false. #33

Closed
JimBobSquarePants opened this issue Mar 16, 2018 · 2 comments
Closed

Cannot save an entity when fireEvents is set to false. #33

JimBobSquarePants opened this issue Mar 16, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@JimBobSquarePants
Copy link

using .Save(object, false) against the current master branch.

https://github.com/umco/umbraco-fluidity/blob/04feb1d4b83ccc33bb2d03e7a3d29dd01b731d65/src/Fluidity/Data/DefaultFluidityRepository.cs#L135

The code sets the args to null on line 113 but then tries to access a property on that reference.

      public object Save(object entity, bool fireEvents = true)
        {
            // I AM NULL
            SavingEntityEventArgs args = null;

            if (fireEvents)
            {
                var existing = Get(entity.GetPropertyValue(_collection.IdProperty));
               
                // I AM ONLY SET HERE
                args = new SavingEntityEventArgs
                {
                    Entity = new BeforeAndAfter<object>
                    {
                        Before = existing,
                        After = entity
                    }
                };

                Fluidity.OnSavingEntity(args);

                if (args.Cancel)
                    return args.Entity.After;

                entity = args.Entity.After;
            }

            // I AM NULL HERE!
            Db.Save(args.Entity.After);

            if (fireEvents)
            {
                Fluidity.OnSavedEntity(args);

                entity = args.Entity.After;
            }

            return entity;
        }
mattbrailsford added a commit that referenced this issue Mar 16, 2018
@mattbrailsford
Copy link
Owner

Good spot. I should be calling save on the entity variable not the one in the event args. I've pushed a fix and should be available in the nightly shortly.

@mattbrailsford mattbrailsford added this to the 1.0.2 milestone Mar 16, 2018
@mattbrailsford mattbrailsford self-assigned this Mar 16, 2018
@JimBobSquarePants
Copy link
Author

Nice one, thanks! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants