Beispiel #1
0
        /// <summary>
        /// Sets the owner of this group to the specified new owner
        /// </summary>
        public async Task SetOwnerAsync(Entity newOwner)
        {
            // Change locally
            this.Owner_Id = newOwner.Id;

            using (VooperContext context = new VooperContext(VooperContext.DBOptions))
            {
                // Change in DB
                Group dummy = new Group {
                    Id = this.Id, Owner_Id = newOwner.Id
                };
                context.Groups.Attach(dummy);

                // Set to update owner field
                context.Entry(dummy).Property(x => x.Owner_Id).IsModified = true;
                await context.SaveChangesAsync();
            }

            // Set top owner to new owner
            Entity topOwner = await Entity.FindAsync(newOwner.Id);

            // Scale up to top owner
            while (topOwner is Group)
            {
                topOwner = await((Group)topOwner).GetOwner();
            }

            // By this point the top owner should be a user
            // Add that user to this group
            await AddMember((User)topOwner);
        }
Beispiel #2
0
        public async Task SetOwnerAsync(Entity newOwner)
        {
            // Set locally
            Owner_Id = newOwner.Id;

            using (VooperContext context = new VooperContext(VooperContext.DBOptions))
            {
                // Set in DB
                StockObject dummy = new StockObject {
                    Id = this.Id, Owner_Id = Owner_Id
                };
                context.Attach(dummy);
                context.Entry(dummy).Property(x => x.Owner_Id).IsModified = true;

                await context.SaveChangesAsync();
            }
        }