Beispiel #1
0
        static async Task UpdateEntityLoadedInSameContext()
        {
            using (var context = new PersistenceContext())
            {
                var appleCard = await context.GiftCards.SingleAsync(i => i.Id == Guid.Parse(AppleCardId));

                appleCard.SetProviderName("Apple Store Gift Card");

                context.Entry(appleCard.ExpiryDate).State = EntityState.Detached;
                appleCard.SetExpirationDate(ExpirationDate.Create(DateTime.UtcNow.AddMonths(2)).Value);
                context.Entry(appleCard.ExpiryDate).State = EntityState.Modified;

                await context.SaveChanges();
            }
        }
Beispiel #2
0
        private static void _NoteSeed(PersistenceContext context)
        {
            var ian  = context.Users.Where(u => u.UserId == "ian").FirstOrDefault();
            var zach = context.Users.Where(u => u.UserId == "zach").FirstOrDefault();

            var kauffman = new Models.Pin()
            {
                Latitude  = 40.819661,
                Longitude = -96.70041,
                Name      = "Kauffman",
                PinId     = "kauf"
            };

            var fuse = new Models.Pin()
            {
                Latitude  = 40.81442,
                Longitude = -96.710235,
                Name      = "FUSE",
                PinId     = "fuse"
            };

            var destinations = new Models.Pin()
            {
                Latitude  = 40.826233,
                Longitude = -96.70155,
                Name      = "Destinations",
                PinId     = "dest",
            };

            kauffman.Notes = new List <Models.Note>
            {
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Make sure to teach class",
                    Pin     = kauffman,
                    NoteId  = "TN1"
                },
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Attend the weekly standup on Thursday",
                    Pin     = kauffman,
                    NoteId  = "TN2"
                },
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Don't eat the donuts",
                    Pin     = kauffman,
                    NoteId  = "TN3"
                },
            };

            fuse.Notes = new List <Models.Note>
            {
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Use the FUSE wifi, it is faster than DPL",
                    Pin     = fuse,
                    NoteId  = "TN4"
                },
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Avoid the elevator",
                    Pin     = fuse,
                    NoteId  = Guid.NewGuid().ToString()
                }
            };

            destinations.Notes = new List <Models.Note>
            {
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "Grab a coffee before heading to Kauffman, you'll thank yourself later",
                    Pin     = destinations,
                    NoteId  = "TN5"
                },
                new Models.Note()
                {
                    Added   = DateTime.Now,
                    Content = "It's a longer walk than you think",
                    Pin     = destinations,
                    NoteId  = "TN6"
                }
            };

            ian.Pins = new List <Models.Pin> {
                kauffman, fuse
            };
            zach.Pins = new List <Models.Pin> {
                destinations
            };

            context.Entry(ian).State  = EntityState.Modified;
            context.Entry(zach).State = EntityState.Modified;

            context.SaveChanges();
        }
Beispiel #3
0
 public void Update(T entity)
 {
     context.Entry(entity).State = EntityState.Modified;
 }