Exemplo n.º 1
0
        public bool CreateDefaults()
        {
            bool aboutIsEmpty = AboutRepository.IsEmpty().GetAwaiter().GetResult();

            //aboutIsEmpty = false;
            if (aboutIsEmpty == false)
            {
                return(false);
            }
            if (aboutIsEmpty)
            {
                try
                {
                    var newAbout = new About
                    {
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now,
                        photo      = $@"http://res.cloudinary.com/djqq6o8su/image/upload/mkvg51472rnjves4etg0",
                        title      = "Mr Photographer",
                        desc       = "Photographer based in Somewhere"
                    };
                    AboutRepository.Insert(newAbout);
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool galleryIsEmpty = GalleryRepository.IsEmpty().GetAwaiter().GetResult();

            //galleryIsEmpty = false;
            if (galleryIsEmpty)
            {
                try
                {
                    string[] names = new string[] { "People", "Landscape" };
                    foreach (var name in names)
                    {
                        var newItem = new Gallery
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        GalleryRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool linkIsEmpty = LinkRepository.IsEmpty().GetAwaiter().GetResult();

            //linkIsEmpty = false;
            if (linkIsEmpty)
            {
                try
                {
                    string[] names = new string[] { "yourfacebookname", "yourinsntagramname", "yourtwittername", "youryourtubename" };
                    foreach (var name in names)
                    {
                        var newItem = new Link
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        LinkRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool logoIsEmpty = LogoRepository.IsEmpty().GetAwaiter().GetResult();

            //logoIsEmpty = false;
            if (logoIsEmpty)
            {
                try
                {
                    string[] photos = new string[] { "http://res.cloudinary.com/djqq6o8su/image/upload/iwrwnlkuxlbypgdn05kp" };
                    foreach (var photo in photos)
                    {
                        var newItem = new Logo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            photo      = photo
                        };
                        LogoRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool slideIsEmpty = SlideRepository.IsEmpty().GetAwaiter().GetResult();

            //slideIsEmpty = false;
            if (slideIsEmpty)
            {
                try
                {
                    string[] names = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/rrcbpzjxm5mesjptu9lc",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/iib9veyowj3wpyirbmlo",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/qgo6zbmwwd0kyanaoynz"
                    };
                    foreach (var name in names)
                    {
                        var newItem = new Slide
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        SlideRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool photoIsEmpty = PhotoRepository.IsEmpty().GetAwaiter().GetResult();

            //photoIsEmpty = false;
            if (photoIsEmpty)
            {
                try
                {
                    string[] names = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tub2v7olse0lwbq9vzrv",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/hvxogea37wkzqv5o6kkv",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/dp62d2vwochkoy2y82ee",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/lifml3ceohhebylxgue6",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/ki6pdlhihsvaakimfnml",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/itwquw92jfpht6yi1ilk",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/jplpld8tp4bxvskdpdzr"
                    };
                    string[] names2 = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/vp8ahga7g1h8f6zx2d0x",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/ozljewvxh83ahvob1aml",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tgrcyaoqx8jwi7mksakd",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/nnsii3wvw6gn40qcldwf",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/e23tgxmvw8jkeje3apjk",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tb0rpo4gvhxv0cyyb31z",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/k90gojfb903m7hoknvs5",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/yqmqqvltyfgt6wbza9zg",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/vrlwiz6u8gcrygbruzw3",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/xapqjqz9vs5kwhqh0cr5"
                    };
                    var galleryPeople    = GalleryRepository.GetAsync(item => item.name == "People").GetAwaiter().GetResult().FirstOrDefault();
                    var galleryLandscape = GalleryRepository.GetAsync(item => item.name == "Landscape").GetAwaiter().GetResult().FirstOrDefault();
                    foreach (var name in names)
                    {
                        var newItem = new Photo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name,
                            Gallery    = galleryPeople
                        };
                        PhotoRepository.Insert(newItem);
                    }
                    foreach (var name in names2)
                    {
                        var newItem = new Photo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name,
                            Gallery    = galleryLandscape
                        };
                        PhotoRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }

            bool userIsEmpty = UserManager.Users.Count() == 0;

            if (userIsEmpty)
            {
                //var user = new ApplicationUser
                //{
                //    ApiToken = "some",
                //    UserName = "******",
                //    Email = "*****@*****.**",
                //    EmailConfirmed = true,
                //    DateAdd = DateTime.Now,
                //    DateUpd = DateTime.Now
                //};
                //await UserManager.CreateAsync(user, "admin");
                ApplicationDbInitializer.SeedRoles(RoleManager);
                ApplicationDbInitializer.SeedUsers(UserManager, appSettings);
                //await SaveAsync();
                //new SignInManager<User>().SignInAsync
                //UserManager.Users.ToList().ForEach( async(user)=> {
                //    await _userManager.DeleteAsync(user);
                //});
            }

            if (aboutIsEmpty || galleryIsEmpty || linkIsEmpty || logoIsEmpty || photoIsEmpty || slideIsEmpty || userIsEmpty)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }