static void Main()
        {
            string filePath = Path.Combine(Environment.CurrentDirectory, @"C:\Users\Administrator\Desktop\DataHierarchyDefinition.xml");

            XmlDocument doc = new XmlDocument();
            doc.Load(filePath);

            var paramsList = doc.GetElementsByTagName("UsagePatternParams");

            var NameValue = new Dictionary<string,string> { };

            for (int i = 0; i < paramsList.Count; i++)
            {
                NameValue.Add(paramsList.Item(i).SelectNodes("Name").Item(0).InnerText, paramsList.Item(i).SelectNodes("Value").Item(0).InnerText);
            }

            foreach (var item in NameValue)
            {
                Console.WriteLine("{0}:{1}",item.Key,item.Value);
            }

            var newStore = new MyBooks();

             foreach (var item in NameValue)
             {
                 var prop = newStore.GetType().GetProperty(item.Key);
                 if (prop != null)
                {
                    //prop.SetValue(newStore,item.Value);
                }
             }
             Console.WriteLine("{0}:{1}", newStore.Payer, newStore.OrderTime);
            Console.ReadLine();
        }
 protected void ddCategory_SelectedIndexChanged(object sender, EventArgs e)
 {
     SearchMessage.Text = "";
     using (MyBooks mb = new MyBooks())
     {
         int s;
         if (ddCategory.SelectedItem.Text == "All")
         {
             var q4 = from x in mb.Books select x;
             if (q4.Count() != 0)
             {
                 DataList1.DataSource = q4.ToList();
                 DataList1.DataBind();
             }
         }
         else
         {
             s = Convert.ToInt32(ddCategory.SelectedValue);
             var q4 = from x in mb.Books where (x.CategoryID == s) select x;
             if (q4.Count() != 0)
             {
                 DataList1.DataSource = q4.ToList();
                 DataList1.DataBind();
             }
         }
     }
 }
        public async Task <bool> ReturnBooks(MyBooks returnBooks)
        {
            var status         = false;
            var userBooksExist = await _libraryRepo.GetUserBooks(returnBooks.UserId);

            if (userBooksExist.Count > 0)
            {
                foreach (var bookId in returnBooks.BookIds)
                {
                    if (userBooksExist.Any(bs => bs.BookId == bookId))
                    {
                        //remove book from mylist and add book to store
                        status = await _libraryRepo.RemoveMyBooksBackToStore(returnBooks.UserId, bookId);
                    }
                    else
                    {
                        throw new Exception($"No such bookId - {bookId} available with you to return!.");
                    }
                }
            }
            else
            {
                throw new Exception("No book available with you to return!.");
            }

            return(status);
        }
        public async Task <bool> BorrowBooks(MyBooks borrowBooks)
        {
            var userBooks      = new List <DataModel.UserBook>();
            var bookinStores   = new List <DataModel.BookStore>();
            var userBooksExist = new List <DataModel.UserBook>();

            if (borrowBooks.BookIds.Count > 0)
            {
                if (borrowBooks.BookIds.Count > 2)
                {
                    throw new Exception("You can't borrow more then 2 books at any point of time!.");
                }
                if (borrowBooks.BookIds.Count > 1 && borrowBooks.BookIds.Distinct().Count() == 1)
                {
                    throw new Exception("Only 1 copy of a book can be borrowed at any point of time!.");
                }

                userBooksExist = await _libraryRepo.GetUserBooks(borrowBooks.UserId);

                if (userBooksExist.Count == 2 || (userBooksExist.Count + borrowBooks.BookIds.Count) > 2)
                {
                    throw new Exception($"You can't borrow more then 2 books at any point of time!. You have already {userBooksExist.Count} nos of book(s) available in your borrowed list.");
                }
                if (userBooksExist.Any(ub => borrowBooks.BookIds.Contains(ub.BookId)))
                {
                    throw new Exception("Only 1 copy of a book can be borrowed at any point of time!.");
                }

                bookinStores = await _libraryRepo.GetStockBooks(borrowBooks.BookIds);

                foreach (var bookId in borrowBooks.BookIds)
                {
                    if (bookinStores.Any(bs => bs.BookId == bookId))
                    {
                        bookinStores.Where(bs => bs.BookId == bookId).FirstOrDefault().StockCount--;
                        userBooks.Add(new DataModel.UserBook()
                        {
                            UserId      = borrowBooks.UserId,
                            BookId      = bookId,
                            CreatedDate = DateTime.UtcNow,
                            UpdatedDate = DateTime.UtcNow
                        });
                    }
                    else
                    {
                        throw new Exception($"bookId-{bookId} not avaible in store at this moment.");
                    }
                }
                return(await _libraryRepo.BorrowBooks(userBooks, bookinStores));
            }
            else
            {
                return(false);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (MyBooks mb = new MyBooks())
         {
             DataList1.DataSource = mb.Books.ToList <Book>();
             DataList1.DataBind();
         }
     }
 }
Exemple #6
0
        private void btnShowBooks_Click(object sender, EventArgs e)
        {
            MyBooks MyBookCollections = new MyBooks();
            string  msg = "";

            foreach (var book in MyBookCollections)
            {
                msg = msg + book + "\n";
            }

            MessageBox.Show(msg, "許清榮的電腦相關著作");
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var getMovieInfo = new Movies();
            var getBookInfo  = new MyBooks();
            var mySoda       = new FavSoda("Coke", 2);
            var getCityName  = new FavCity();

            getMovieInfo.PlayMovie();
            getBookInfo.OpenBook();
            mySoda.PrintSodaName();
            getCityName.GoToCity();
        }
Exemple #8
0
        public ActionResult Add_Library(int id)
        {
            var     book    = db.Books.Find(id);
            var     user    = db.Users.Where(x => x.USERNAME == User.Identity.Name).FirstOrDefault();
            MyBooks new_add = new MyBooks();

            new_add.Book = book;
            new_add.User = user;
            db.MyBooks.Add(new_add);
            db.SaveChanges();
            return(RedirectToAction("TheBook", "Book", new { id = book.BOOK_ID }));
        }
        public async Task <ActionResult> ReturnBooks(MyBooks returnBooks)
        {
            try
            {
                var result = await _libraryLogic.ReturnBooks(returnBooks);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(Helper.CreateApiError(ex));
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            //Book book = new Book();
            //book.BookName = "ASP.NET 4.0程序设计";
            //book.ISBN = "0000000000";
            //book.Price = 59.8;

            //Book book = new Book()
            //{
            //    BookName = "ASP.NET 4.0程序设计",
            //    ISBN = "0000000000",
            //    Price = 59.8
            //};

            //Book book = new Book
            //{
            //    BookName = "ASP.NET 4.0程序设计",
            //    ISBN = "0000000000",
            //    Price = 59.8
            //};


            //Book book = new Book("编程书籍")
            //  {
            //      BookName = "ASP.NET 4.0程序设计",
            //      ISBN = "0000000000",
            //      Price = 59.8
            //  };
            //Console.WriteLine(book.ToString());
            //实例化MyBooks类,并使用对象初始化语法直接初始化内部成员
            MyBooks mybooks = new MyBooks
            {
                ProgramBook = new Book("编程书籍")
                {
                    BookName = "ASP.NET 4.0程序设计",
                    ISBN     = "0000000000",
                    Price    = 59.8
                },
                StoryBook = new Book("小说")
                {
                    BookName = "官场现形记",
                    ISBN     = "1111111111",
                    Price    = 59.8
                }
            };

            ////控制台窗口输出
            Console.WriteLine(mybooks.ProgramBook.ToString() + Environment.NewLine + mybooks.StoryBook.ToString());
        }
Exemple #11
0
        static void Main(string[] args)
        {
            //Book book = new Book();
            //book.BookName = "ASP.NET 3.5程序设计";
            //book.ISBN = "0000000000";
            //book.Price = 59.8;

            //Book book = new Book()
            //{
            //    BookName = "ASP.NET 3.5程序设计",
            //    ISBN = "0000000000",
            //    Price = 59.8
            //};

            //Book book = new Book
            //{
            //    BookName = "ASP.NET 3.5程序设计",
            //    ISBN = "0000000000",
            //    Price = 59.8
            //};

            //Book book = new Book("编程书籍")
            //  {
            //      BookName = "ASP.NET 3.5程序设计",
            //      ISBN = "0000000000",
            //      Price = 59.8
            //  };
            //Console.WriteLine(book.ToString());
            //实例化MyBooks类,并使用对象初始化语法直接初始化内部成员
            MyBooks mybooks = new MyBooks
            {
                ProgramBook = new Book("编程书籍")
              {
                  BookName = "ASP.NET 3.5程序设计",
                  ISBN = "0000000000",
                  Price = 59.8
              },
                StoryBook = new Book("小说")
                {
                    BookName = "官场现形记",
                    ISBN = "1111111111",
                    Price = 59.8
                }
            };
            //控制台窗口输出
            Console.WriteLine(mybooks.ProgramBook.ToString() + Environment.NewLine + mybooks.StoryBook.ToString());
        }
Exemple #12
0
        public void TestInitialization()
        {
            _libraryLogic = new LibraryLogic(_mockMapper.Object, _mockLibraryRepo.Object);
            _bookDMList   = Builder <DataModel.Book> .CreateListOfSize(2).Build().ToList();

            _bookVMList = Builder <Book> .CreateListOfSize(2).Build().ToList();

            _borrowBook = Builder <MyBooks> .CreateNew().Build();

            _borrowBook.UserId  = 1;
            _borrowBook.BookIds = new List <int>()
            {
                1, 2
            };
            _bookStoreDMList = Builder <DataModel.BookStore> .CreateListOfSize(2).Build().ToList();

            _userBookDMList = Builder <DataModel.UserBook> .CreateListOfSize(2).Build().ToList();
        }
        public void TestInitialization()
        {
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            _controller = new LibraryController(_mockLibraryLogic.Object)
            {
                ControllerContext = controllerContext
            };

            _bookVMList = Builder <Book> .CreateListOfSize(2).Build().ToList();

            _borrowBook = Builder <MyBooks> .CreateNew().Build();

            _borrowBook.UserId  = 1;
            _borrowBook.BookIds = new List <int>()
            {
                1, 2
            };
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            SearchMessage.Text = "";
            using (MyBooks mb = new MyBooks())
            {
                if (ddCategory.SelectedItem.Text == "All")
                {
                    if (txtSearch.Text != null)
                    {
                        switch (ddDetails.SelectedValue)
                        {
                        case "Author":

                            catid = Convert.ToInt32(ddCategory.SelectedValue);
                            var q = from x in mb.Books where x.Author.Contains(txtSearch.Text) select x;
                            if (q.Count() != 0)
                            {
                                DataList1.DataSource = q.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        case "Title":
                            catid = Convert.ToInt32(ddCategory.SelectedValue);
                            var q1 = from x in mb.Books where x.Title.Contains(txtSearch.Text) select x;
                            if (q1.Count() != 0)
                            {
                                DataList1.DataSource = q1.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        case "ISBN":
                            catid = Convert.ToInt32(ddCategory.SelectedValue);
                            var q2 = from x in mb.Books where x.ISBN == (txtSearch.Text) select x;
                            if (q2.Count() != 0)
                            {
                                DataList1.DataSource = q2.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        default:
                            SearchMessage.Text = "Failed";
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            break;
                        }
                    }
                    else
                    {
                        SearchMessage.Text = "Failed";
                        Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                    }
                }
                else
                {
                    catid = Convert.ToInt32(ddCategory.SelectedValue);
                    if (txtSearch.Text != null)
                    {
                        switch (ddDetails.SelectedValue)
                        {
                        case "Author":

                            //catid = Convert.ToInt32(CategoryDL.SelectedValue);
                            var q = from x in mb.Books where x.Author.Contains(txtSearch.Text) && x.CategoryID == catid select x;
                            if (q.Count() != 0)
                            {
                                DataList1.DataSource = q.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        case "Title":
                            //catid = Convert.ToInt32(CategoryDL.SelectedValue);
                            var q1 = from x in mb.Books where x.Title.Contains(txtSearch.Text) && x.CategoryID == catid select x;
                            if (q1.Count() != 0)
                            {
                                DataList1.DataSource = q1.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        case "ISBN":
                            //catid = Convert.ToInt32(CategoryDL.SelectedValue);
                            var q2 = from x in mb.Books where x.ISBN == (txtSearch.Text) && x.CategoryID == catid select x;
                            if (q2.Count() != 0)
                            {
                                DataList1.DataSource = q2.ToList();
                                DataList1.DataBind();
                            }
                            else
                            {
                                SearchMessage.Text = "Failed";
                                Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            }
                            break;

                        default:
                            SearchMessage.Text = "Failed";
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                            break;
                        }
                    }

                    else
                    {
                        SearchMessage.Text = "Failed";
                        Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                    }
                }
            }
        }