Exemple #1
0
        public async Task <IActionResult> Create(LibAccountData data)
        {
            // TODO: Need to check that Owner information is unique.
            if (ModelState.IsValid)
            {
                var newOwner = new Person
                {
                    FirstName = data.Owner.FirstName,
                    LastName  = data.Owner.LastName
                };

                var newAccount = new LibAccount
                {
                    // TODO: Change the library account init to accept an owner and set the items checked out to 0
                    Owner           = newOwner,
                    ItemsCheckedOut = 0
                };

                try
                {
                    _context.LibAccounts.Add(newAccount);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            // TODO: Make this redirect more informative.
            return(RedirectToAction(nameof(Create)));
        }
        public async Task <Account> LoginAsync(string pin)
        {
            var query = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("oauth_verifier", pin)
            };
            var response = await owner.PostAsync("https://api.twitter.com/oauth/access_token", consumer, oauth, query);

            var data = HttpUtility.ParseQueryString(response);

            var account = new LibAccount
            {
                Consumer = consumer,
                Oauth    = new Token(data["oauth_token"], data["oauth_token_secret"]),
                ID       = long.Parse(data["user_id"])
            };

            account.User = await owner.VerifyCredentialsAsync(account);

            return(account);
        }
Exemple #3
0
        public static void Initialize(LibraryContext context, UserManager <AppUser> usrMgr, RoleManager <IdentityRole> roleMgr)
        {
            context.Database.EnsureCreated();

            if (context.BookItems.Any())
            {
                return;
            }

            InitializeRoles(roleMgr);
            InitializeUsers(usrMgr);

            var bookItems = new BookItem[]
            {
                new BookItem {
                    ISBN   = "978771601184",
                    Author = "Chic Scott",
                    Title  = "Ski Trails in the Canadian Rockies"
                },
                new BookItem {
                    ISBN   = "978771601185",
                    Author = "Chic Scott Jr",
                    Title  = "Ski Trails in the Canadian Rockies"
                },
                new BookItem {
                    ISBN   = "978771601186",
                    Author = "Robert Greene",
                    Title  = "48 Laws of Power"
                },
                new BookItem {
                    ISBN   = "978771601187",
                    Author = "Be Here Now",
                    Title  = "Ram Dass"
                },
                new BookItem {
                    ISBN   = "978771601188",
                    Author = "Jocko Willink",
                    Title  = "Extreme Ownership"
                },
                new BookItem {
                    ISBN   = "978771601189",
                    Author = "Thich Nhat Hanh",
                    Title  = "How to Eat"
                },
                new BookItem {
                    ISBN   = "978771601190",
                    Author = "Dale Carnegie",
                    Title  = "How to Win Friends & Influence People"
                },
                new BookItem {
                    ISBN   = "978771601191",
                    Author = "Christina Wodtke",
                    Title  = "Radical Focus"
                },
                new BookItem {
                    ISBN   = "978771601192",
                    Author = "Jason Fried & David Hansson",
                    Title  = "ReWork"
                },
                new BookItem {
                    ISBN   = "978771601193",
                    Author = "Yuval Noah Harari",
                    Title  = "Sapiens"
                },
                new BookItem {
                    ISBN   = "978771601194",
                    Author = "Gregory David Roberts",
                    Title  = "Shantaram"
                },
                new BookItem {
                    ISBN   = "978771601195",
                    Author = "John Sonmez",
                    Title  = "Soft Skills"
                },
                new BookItem {
                    ISBN   = "978771601196",
                    Title  = "Soft Skills Again",
                    Author = "John Sonmez"
                },
                new BookItem {
                    ISBN = "978771601197",

                    Title = "Tao of Wu", Author = "RZA"
                },

                new BookItem {
                    ISBN = "978771601198",

                    Title  = "The Alchemist",
                    Author = "Paulo Coelho"
                },

                new BookItem {
                    ISBN   = "978771601199",
                    Title  = "The Art of War",
                    Author = "Sun Tzu",
                },

                new BookItem {
                    ISBN   = "978771601200",
                    Title  = "The Book of Mistakes",
                    Author = "Skip Prichard"
                },
                new BookItem {
                    ISBN   = "978771601201",
                    Title  = "The Culture Code",
                    Author = "Daniel Coyle"
                },
                new BookItem {
                    ISBN   = "978771601202",
                    Title  = "The Four Agreements",
                    Author = "Don Miguel Ruiz"
                }
            };

            foreach (BookItem item in bookItems)
            {
                context.BookItems.Add(item);
            }
            context.SaveChanges();

            var people = new Person[] {
                new Person {
                    FirstName = "Mike",
                    LastName  = "Persson"
                },
                new Person {
                    FirstName = "Heather",
                    LastName  = "Chamberlain"
                },
                new Person {
                    FirstName = "Elizabeth",
                    LastName  = "Seybold"
                }
            };

            foreach (Person item in people)
            {
                context.People.Add(item);
            }
            context.SaveChanges();

            var libAcccounts = new LibAccount[] {
                new LibAccount {
                    Owner           = people.Single(p => p.LastName == "Persson"),
                    ItemsCheckedOut = 1
                },
                new LibAccount {
                    Owner           = people.Single(p => p.LastName == "Chamberlain"),
                    ItemsCheckedOut = 1
                },
                new LibAccount {
                    Owner           = people.Single(p => p.LastName == "Seybold"),
                    ItemsCheckedOut = 2
                }
            };

            foreach (LibAccount item in libAcccounts)
            {
                context.LibAccounts.Add(item);
            }
            context.SaveChanges();

            var bookLoans = new BookLoan[] {
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Persson").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601184").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01")
                },
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Chamberlain").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601185").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01")
                },
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Chamberlain").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601199").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01"),
                    ReturnedDate = DateTime.Parse("2020-12-4")
                },
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Seybold").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601201").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01")
                },
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Seybold").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601202").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01")
                },
                new BookLoan
                {
                    LibAccountID = libAcccounts.Single(l => l.Owner.LastName == "Seybold").ID,
                    BookItemID   = bookItems.Single(b => b.ISBN == "978771601198").ID,
                    BorrowedDate = DateTime.Now,
                    DueDate      = DateTime.Parse("2020-09-01"),
                    ReturnedDate = DateTime.Parse("2020-12-4")
                },
            };

            foreach (BookLoan item in bookLoans)
            {
                context.BookLoans.Add(item);
            }
            context.SaveChanges();
        }