Esempio n. 1
0
 public string AddBook(MyBook s) // trả về tổng số lượng
 {
     try
     {
         if (s.TinhTrang == 0)            //sách này còn bán
         {
             if (Session["cart"] == null) //chưa có giỏ hàng
             {
                 Session["cart"] = new GioHang();
                 ((GioHang)Session["cart"]).AddItem(s);
                 return(((GioHang)(Session["cart"])).GenerateResult());
             }
             else //đã có giỏ hàng
             {
                 ((GioHang)Session["cart"]).AddItem(s);
                 return(((GioHang)(Session["cart"])).GenerateResult());
             }
         }
         else
         {
             return(((GioHang)(Session["cart"])).GenerateResult());  //trả về số sách hiện tại trong giỏ 0 tăng thêm gì
         }
     }
     catch (Exception) { return("0/0"); }
 }
Esempio n. 2
0
        public ActionResult Update(MyBookCRUDModel model)
        {
            if (Session["LoggedUser"] != null)
            {
                MyBook myBook = myBookOperation.GetById(model.BookId);

                myBook.BookId     = model.BookId;
                myBook.Name       = model.Name;
                myBook.Writer     = model.Writer;
                myBook.Image      = model.ImagePath;
                myBook.CategoryId = model.CategoryId;

                #region Upload

                string Imagee = string.Empty;

                if (model.ImageFile != null)
                {
                    Imagee = model.ImageFile.FileName;
                    model.ImageFile.SaveAs(Server.MapPath("~/Content/Picture/") + model.ImageFile.FileName);
                    myBook.Image = Imagee;
                }
                #endregion

                myBookOperation.Update(myBook);
            }

            return(RedirectToAction("Index", "MyBook"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MyBook = await _context.MyBook.FirstOrDefaultAsync(m => m.ID == id);

            if (String.IsNullOrEmpty(MyBook.CheckedDate.ToString()))
            {
                MyBook.UserName = User.Identity.Name;
            }
            else
            {
                if (string.Compare(MyBook.UserName, User.Identity.Name) != 0)
                {
                    return(RedirectToPage("./bookerror"));
                }
            }
            if (MyBook == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 4
0
        public ActionResult Update(int id = 0)
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                MyBook myBook = myBookOperation.GetById(id);

                if (myBook != null)
                {
                    MyBookCRUDModel myBookCRUDModel = new MyBookCRUDModel();


                    List <Category> categoryList = categoryOperation.GetAllCategory(appUser.AppUserId);
                    myBookCRUDModel.CategoryList = new SelectList(categoryList, "CategoryId", "Name");

                    myBookCRUDModel.BookId     = myBook.BookId;
                    myBookCRUDModel.Name       = myBook.Name;
                    myBookCRUDModel.Writer     = myBook.Writer;
                    myBookCRUDModel.ImagePath  = myBook.Image;
                    myBookCRUDModel.CategoryId = myBook.CategoryId;

                    return(View(myBookCRUDModel));
                }
                else
                {
                    return(RedirectToAction("Index", "MyBook"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
// <Snippet1>
    private void CreateBook(string filename)
    {
        try
        {
            // Create instance of XmlSerializerNamespaces and add the namespaces.
            XmlSerializerNamespaces myNameSpaces = new XmlSerializerNamespaces();
            myNameSpaces.Add("BookName", "http://www.cpandl.com");

            // Create instance of XmlSerializer and specify the type of object
            // to be serialized.
            XmlSerializer mySerializerObject =
                new XmlSerializer(typeof(MyBook));

            TextWriter myWriter = new StreamWriter(filename);
            // Create object to be serialized.
            MyBook myXMLBook = new MyBook();

            myXMLBook.Author      = "XMLAuthor";
            myXMLBook.BookName    = "DIG THE XML";
            myXMLBook.Description = "This is a XML Book";

            MyPriceClass myBookPrice = new MyPriceClass();
            myBookPrice.Price   = (decimal)45.89;
            myBookPrice.Units   = "$";
            myXMLBook.BookPrice = myBookPrice;

            // Serialize the object.
            mySerializerObject.Serialize(myWriter, myXMLBook, myNameSpaces);
            myWriter.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception :" + e.Message + "Occurred");
        }
    }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine(4 % 5);
            Console.ReadLine();
            Operation operation = Operation.Create | Operation.Query;

            Console.WriteLine(operation);
            Console.ReadLine();
            //配置初始化
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <MyBook, Book>();
                cfg.RecognizeAlias("book_number", "ISBN");
            });

            //书本
            MyBook book = new MyBook()
            {
                book_number = "55552445545",
                Name        = "朝花夕拾",
                author      = new Author()
                {
                    firstName = "鲁",
                    lastName  = "迅"
                }
            };

            var _book = AutoMapper.Mapper.Map <MyBook, Book>(book);
        }
Esempio n. 7
0
    //private void Tick (object state)
    //{
    //    GetText();
    //}

    IEnumerator GetText()
    {
        using (UnityWebRequest www = UnityWebRequest.Get(url_server))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
                JsonPanel.text = "isNetworkError";
            }
            else if (www.isHttpError)
            {
                Debug.Log(www.error);
                JsonPanel.text = "isHttpError";
            }
            else
            {
                MyBook myJsonObject = new MyBook();
                myJsonObject = JsonUtility.FromJson <MyBook>(www.downloadHandler.text);

                JsonPanel.text   = www.downloadHandler.text;
                AuthorPanel.text = myJsonObject.author;

                JsonPanel.text = "In GetText() in else";

                // Show results as text
                Debug.Log(www.downloadHandler.text);
                Debug.Log(myJsonObject.create_date);
                Debug.Log(AuthorPanel.text);
            }
        }
    }
        public async Task <MyBook> HandleAsync(AppendNewBookToMyBookList request, CancellationToken cancellationToken)
        {
            var book = new MyBook(request.Author, request.Title);

            book = await _myBookDataStorage.CreateAsync(book, cancellationToken);

            return(book);
        }
Esempio n. 9
0
 public void Add(MyBook myBook)
 {
     using (context)
     {
         context.MyBooks.Add(myBook);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 static void Main(String[] args)
 {
     string title = Console.ReadLine();
     string author = Console.ReadLine();
     int price = int.Parse(Console.ReadLine());
     Book new_novel = new MyBook(title, author, price);
     new_novel.display();
 }
Esempio n. 11
0
        static void RunAbstractClasses()
        {
            var title    = Console.ReadLine();
            var author   = Console.ReadLine();
            var price    = Int32.Parse(Console.ReadLine());
            var newNovel = new MyBook(title, author, price);

            newNovel.Display();
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            MyBook myBook = await db.MyBooks.FindAsync(id);

            db.MyBooks.Remove(myBook);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
    static void Main(String[] args)
    {
        String title     = Console.ReadLine();
        String author    = Console.ReadLine();
        int    price     = Int32.Parse(Console.ReadLine());
        Book   new_novel = new MyBook(title, author, price);

        new_novel.display();
    }
Esempio n. 14
0
        public IActionResult Details(int id, int bookId, int person)
        {
            ViewBag.Id = id;

            MyBook detail = db.MyBooks.Where(x => x.BookId == bookId && x.UserId == person).SingleOrDefault();

            ViewBag.detail = detail;
            return(View());
        }
Esempio n. 15
0
        public IActionResult AddBook(int id, MyBook book, UploadModel upload)
        {
            String random  = RandomString(10);
            var    FileDic = "Files";

            string FilePath = System.IO.Path.Combine(hostingEnv.WebRootPath, FileDic);

            if (!Directory.Exists(FilePath))
            {
                Directory.CreateDirectory(FilePath);
            }

            var fileName = random + upload.File.FileName;

            var filePath = System.IO.Path.Combine(FilePath, fileName);



            using (FileStream fs = System.IO.File.Create(filePath))

            {
                upload.File.CopyTo(fs);
            }



            if (!ModelState.IsValid)
            {
                return(Redirect("~/Book/AddBook/" + id));
            }
            book.BookImage = "~/Files/" + fileName;
            book.UserId    = id;
            ViewBag.Id     = id;

            db.MyBooks.Add(book);
            db.SaveChanges();
            //if (file != null && file.ContentLength > 0)
            //    try
            //    {
            //        String random = RandomString(10);
            //       string path = Path.Combine(Server.MapPath("~/Upload/"),
            //        Path.GetFileName(random + ".mp4"));
            //        file.SaveAs(path);
            //        book.BookImage = "~/Upload/" + random + ".mp4";
            //        ViewBag.Message = "File uploaded successfully";
            //    }
            //    catch (Exception ex)
            //    {
            //        ViewBag.Message = "ERROR:" + ex.Message.ToString();
            //    }
            //else
            //{
            //    ViewBag.Message = "You have not specified a file.";
            //}
            return(Redirect("~/Home/Profile/" + id));
        }
        public async Task <MyBook> HandleAsync(AppendExistingBookToMyBookList request,
                                               CancellationToken cancellationToken)
        {
            var existingBook = await _queryDispatcher.FetchAsync(new BookQuery(request.BookKey), cancellationToken);

            var book = new MyBook(existingBook);

            book = await _myBookDataStorage.CreateAsync(book, cancellationToken);

            return(book);
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,BookName,AuthorName,BookPrice,BookPublish,Comments")] MyBook myBook)
        {
            if (ModelState.IsValid)
            {
                db.Entry(myBook).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(myBook));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,BookName,AuthorName,BookPrice,BookPublish,Comments")] MyBook myBook)
        {
            if (ModelState.IsValid)
            {
                db.MyBooks.Add(myBook);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(myBook));
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            int    choose;
            MyBook Book = new MyBook();

            Console.WriteLine("----------Menu----------");
            Console.WriteLine("1. Add new Book");
            Console.WriteLine("2. Update a Book");
            Console.WriteLine("3. Delete a Book");
            Console.WriteLine("4.List all Book");
            Console.WriteLine("5. Quit");
            Console.WriteLine("------------------------");

            do
            {
                Console.Write("Please enter your choice: ");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                case 1:
                    Book.Add();
                    break;

                case 2:
                    Console.Write("Input ID to update: ");
                    string idUpdate = Console.ReadLine();
                    Book.Update(idUpdate);
                    break;

                case 3:
                    Console.Write("Input ID to delete: ");
                    string idDelete = Console.ReadLine();
                    Console.Write("Do you really want to delete (Yes/No)?  ");
                    if (Console.ReadLine().ToUpper().Equals("YES"))
                    {
                        Book.Delete(idDelete);
                    }
                    break;

                case 4:
                    Book.Show();
                    break;

                case 5:
                    break;

                default:
                    Console.WriteLine("Please enter number in range 1-5");
                    break;
                }
            } while (choose != 5);
        }
    static void Main(string[] args)
    {
        var reader = new InputReader(false);

        string title  = reader.NextString;
        string author = reader.NextString;
        int    price  = reader.NextInt;

        reader.Close();

        Book book = new MyBook(title, author, price);

        book.Display();
    }
        // GET: MyBooks/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MyBook myBook = await db.MyBooks.FindAsync(id);

            if (myBook == null)
            {
                return(HttpNotFound());
            }
            return(View(myBook));
        }
Esempio n. 22
0
        public void AddBookToMyBook(object sender, EventArgs s)
        {
            Button btn           = (Button)sender;
            var    bookId        = int.Parse(btn.AccessibleName);
            var    myBookService = new MyBookService();
            var    newMyBook     = new MyBook();

            newMyBook.BookId = bookId;
            newMyBook.UserId = Global.UserId;


            myBookService.Add(newMyBook);
            MessageBox.Show("Successfull added!");
        }
Esempio n. 23
0
 public void wirteToExcel(CurrencyRates cur, string name)
 {
     lastRow += 1;
     MySheet.Cells[lastRow, 1] = cur.Base;
     MySheet.Cells[lastRow, 2] = cur.Disclaimer;
     MySheet.Cells[lastRow, 3] = cur.FomatTimeStamp();
     lastRow += 2;
     foreach (var dic in cur.Rates)
     {
         MySheet.Cells[lastRow, 1] = dic.Key;
         MySheet.Cells[lastRow, 2] = dic.Value;
         lastRow += 1;
     }
     MyBook.SaveAs(name);
 }
Esempio n. 24
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MyBook = await _context.MyBook.FirstOrDefaultAsync(m => m.ID == id);

            if (MyBook == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 25
0
        public void AbstractBookTest()
        {
            using (StringWriter writer = new StringWriter())
            {
                string title          = "The Alchemist";
                string author         = "Paulo Coelho";
                int    price          = 248;
                MyBook novel          = new MyBook(title, author, price);
                string expectedOutput = $"Title: {title} Author: {author} Price: {price}";

                Console.SetOut(writer);
                novel.display();

                Assert.AreEqual(expectedOutput, writer.ToString());
            }
        }
Esempio n. 26
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MyBook = await _context.MyBook.FindAsync(id);

            if (MyBook != null)
            {
                _context.MyBook.Remove(MyBook);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 27
0
        public IActionResult MyFav(int id)
        {
            List <MyFav>  list    = db.MyFavs.Where(x => x.UserId == id).ToList();
            List <MyBook> favList = new List <MyBook>();

            foreach (var item in list)
            {
                MyBook book = db.MyBooks.Where(t => t.BookId == item.BookId).SingleOrDefault();
                favList.Add(book);
            }
            List <MyFav> list2 = db.MyFavs.ToList();

            ViewBag.FavList  = favList;
            ViewBag.FavList2 = list2;
            ViewBag.Id       = id;

            return(View());
        }
Esempio n. 28
0
        static void Main(String[] args)
        {
            Console.WriteLine("Title");
            String title = Console.ReadLine();

            Console.WriteLine("Author");
            String author = Console.ReadLine();

            Console.WriteLine("Price");
            int price = Int32.Parse(Console.ReadLine());

            Console.WriteLine();

            // creates an instance of myBook based on console input
            Book new_novel = new MyBook(title, author, price);

            // prints the desired data to the console via the display method
            new_novel.display();
        }
Esempio n. 29
0
        // GET: Books
        public async Task <IActionResult> MyBooks()
        {
            BookThruUser u = _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();


            var list = await _context.Book.ToListAsync();

            var sList = list.Where(y => y.Id == u.Id).ToList();
            var bList = list.Where(y => y.CurrentBidder == u.Email).ToList();

            MyBook myBook = new MyBook
            {
                Sold   = list,
                Bought = bList
            };

            return(View(myBook));
            //return View(await _context.Book.Where(x=>x.Uploaded> DateTime.Now.Date).ToListAsync());
        }
Esempio n. 30
0
    public List<MyBook> GetBooks(string category)
    {
        var book = from b in db.Books
                   from c in b.Categories
                   from a in b.Authors
                   where c.CategoryName.Equals(category)
                   select new { b.BookTitle, a.AuthorName, b.BookISBN, b.BookEntryDate };

        List<MyBook> books = new List<MyBook>();
        foreach (var b in book)
        {
            MyBook bk = new MyBook();
            bk.BookTitle = b.BookTitle;
            bk.Author = b.AuthorName;
            bk.ISBN = b.BookISBN;
            books.Add(bk);
        }
        return books;
    }
Esempio n. 31
0
        public async Task Queryable_Should_Allow_Composition()
        {
            // Arrange
            var comparer  = new MyBookComparer();
            var expected1 = new MyBook
            {
                BookId    = _books[0].Id,
                Name      = _books[0].BookName,
                UnitPrice = _books[0].Price,
                Category  = _books[0].Category,
                Author    = _books[0].Author
            };
            var expected2 = new MyBook
            {
                BookId    = _books[1].Id,
                Name      = _books[1].BookName,
                UnitPrice = _books[1].Price,
                Category  = _books[1].Category,
                Author    = _books[1].Author
            };
            var repository = new DocumentRepository <Book>(_collection);

            // Act
            var products = await repository
                           .Queryable()
                           .Take(2)
                           .Where(b => b.Price.CompareTo(15.00m) > 0)
                           .Select(b => new MyBook
            {
                BookId    = b.Id,
                Name      = b.BookName,
                UnitPrice = b.Price,
                Category  = b.Category,
                Author    = b.Author
            })
                           .ToListAsync();

            // Assert
            Assert.Collection(products,
                              p => Assert.Equal(expected1, p, comparer),
                              p => Assert.Equal(expected2, p, comparer));
        }
Esempio n. 32
0
    void DataBindToRepeater(int currentPage)
    {
        DataTable dt = (DataTable)Session["dt"];

        PagedDataSource pds = new PagedDataSource();

        pds.AllowPaging = true;

        pds.PageSize = 2;

        pds.DataSource = dt.DefaultView;

        lbTotal.Text = pds.PageCount.ToString();

        pds.CurrentPageIndex = currentPage - 1;//当前页数从零开始,故把接受的数减一

        MyBook.DataSource = pds;

        MyBook.DataBind();
    }