Exemplo n.º 1
0
        private static void _UserSeed(PersistenceContext context)
        {
            context.Users.Add(new Models.User()
            {
                AvatarUrl = @"https://avatars0.githubusercontent.com/u/425362?v=3&s=460",
                Email     = "*****@*****.**",
                FirstName = "Ian",
                LastName  = "Cottingham",
                Location  = "Lincoln, NE",
                UserId    = "ian"
            });

            context.Users.Add(new Models.User()
            {
                AvatarUrl = @"https://avatars1.githubusercontent.com/u/4513686?v=3&s=400",
                Email     = "*****@*****.**",
                FirstName = "Zach",
                LastName  = "Christensen",
                Location  = "Lincoln, NE",
                UserId    = "zach"
            });

            context.Users.Add(new Models.User()
            {
                AvatarUrl = @"http://cdn2.insidermonkey.com/blog/wp-content/uploads/2013/01/01-Bill-Gates.jpg",
                Email     = "*****@*****.**",
                FirstName = "Bill",
                LastName  = "Gates",
                Location  = "Seattle, WA",
                UserId    = "bill"
            });

            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void DeleteDepartmentImage(Guid id)
        {
            var db    = new PersistenceContext();
            var image = db.Images.Find(id);

            if (image != null)
            {
                image.Deleted = DateTime.Now;
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public DepartmentImage CreateDepartmentImage(Domain.Image image, Department department)
        {
            var db       = new PersistenceContext();
            var newImage = new Image()
            {
                Name      = image.Name,
                Extension = image.Extension,
                ImageData = image.ImageData
            };

            db.Images.Add(newImage);
            db.SaveChanges();

            return(MapDepartmentImage(newImage));
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        static async Task StoreGiftCards()
        {
            var giftCards = new List <GiftCard>
            {
                new GiftCard(Guid.NewGuid(), "Tesco", ExpirationDate.Create(DateTime.MinValue).Value),
                new GiftCard(Guid.Parse(AppleCardId), "Apple", ExpirationDate.Create(DateTime.MinValue).Value),
                new GiftCard(Guid.NewGuid(), "Marks And Spencer", ExpirationDate.Create(DateTime.MinValue).Value)
            };

            using (var context = new PersistenceContext())
            {
                await context.GiftCards.AddRangeAsync(giftCards);

                await context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 public void Do(Action <UnitOfWork> work)
 {
     try
     {
         work(this);
         if (!canceled)
         {
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         canceled = true;
         throw;
     }
 }
Exemplo n.º 7
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();
        }