Example #1
0
        public async Task <ActionResult> Create(Book book, FormCollection formcollection)
        {
            string imageURL = null;

            try
            {
                imageURL = formcollection["txtImageURL"].ToString();
            }
            catch
            {
                imageURL = "/Content/images/Image.jpg";
            }
            if (ModelState.IsValid)
            {
                var dao = new BookDAO();
                var rs  = dao.Insert(book, imageURL);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ImageBoolID = new SelectList(db.ImageBools, "ImageBoolID", "ImageBoolID", book.ImageBoolID);
            //ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", book.Authors.First().AuthorID);
            ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", book.PublisherID);
            return(View(book));
        }
Example #2
0
        public async Task <ActionResult> PaypalConfirmed()
        {
            try
            {
                BSDBContext db    = new BSDBContext();
                var         model = (CommonConstant.InforPaypal)TempData["InforOrder"];
                int         Id    = model.OrderId;
                OrdersBook  Order = db.OrdersBooks.Find(Id);
                Order.Paid            = true; // Đã thanh toán
                db.Entry(Order).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                var orderBook = new OrderBookDAO().Get(Id);
                historyBankCharging history = new historyBankCharging()
                {
                    email            = orderBook.Email,
                    phone            = orderBook.Phone,
                    fullname         = orderBook.FullName,
                    date_trans       = DateTime.Now,
                    price            = (int)model.Total,
                    order_code       = null,
                    error_text       = null,
                    transaction_info = null,
                    payment_id       = null,
                    payment_type     = "Paypal",
                    secure_code      = null
                };
                db.historyBankChargings.Add(history);
                await db.SaveChangesAsync();

                // giam so luong ton cua cac sách khách đã thanh toán
                foreach (OrdersDetail ordersDetail in Order.OrdersDetails)
                {
                    Book book = db.Books.Find(ordersDetail.BookID);
                    book.TotalQuantity  -= (ordersDetail.Quantity ?? 0); // giảm
                    db.Entry(book).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();
                }

                Session[CommonConstant.cartSession] = null;
                return(Redirect("/hoan-thanh"));
            }
            catch (Exception ex)
            {
                return(View("ThongBaoLoi"));
            }
        }
Example #3
0
        // ok roi.
        public async Task <ActionResult> PaymentConfirmed(string transaction_info, string order_code, int price, string payment_id, string payment_type, string error_text, string secure_code)
        {
            BSDBContext db = new BSDBContext();

            if (error_text == "")
            {
                int        Id    = int.Parse(order_code);
                OrdersBook Order = db.OrdersBooks.Find(Id);
                Order.Paid            = true; // Đã thanh toán
                db.Entry(Order).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                var orderBook = new OrderBookDAO().Get(Id);
                historyBankCharging history = new historyBankCharging()
                {
                    email            = orderBook.Email,
                    phone            = orderBook.Phone,
                    fullname         = orderBook.FullName,
                    date_trans       = DateTime.Now,
                    price            = price,
                    order_code       = order_code,
                    error_text       = error_text,
                    transaction_info = transaction_info,
                    payment_id       = payment_id,
                    payment_type     = payment_type,
                    secure_code      = secure_code
                };
                db.historyBankChargings.Add(history);
                await db.SaveChangesAsync();

                // giam so luong ton cua cac sách khách đã thanh toán
                foreach (OrdersDetail ordersDetail in Order.OrdersDetails)
                {
                    Book book = db.Books.Find(ordersDetail.BookID);
                    book.TotalQuantity  -= (ordersDetail.Quantity ?? 0); // giảm
                    db.Entry(book).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();
                }

                Session[CommonConstant.cartSession] = null;
                return(Redirect("/hoan-thanh"));
            }
            else
            {
                return(View("ThongBaoLoi"));
            }
        }
Example #4
0
        public async Task <int> Handle(CreateBookStoreCommand request, CancellationToken cancellationToken)
        {
            var bookStore = new BookStore
            {
                BookStoreName = request.BookStoreName
            };

            _context.Add(bookStore);

            await _context.SaveChangesAsync(cancellationToken);

            return(bookStore.BookStoreId);
        }
        public async Task <int> Handle(CreateBookCommand request, CancellationToken cancellationToken)
        {
            var objectItem = new BookItem
            {
                BookStoreId = request.BookStoreId,
                BookName    = request.BookName
            };

            _context.Add(objectItem);

            await _context.SaveChangesAsync(cancellationToken);

            return(objectItem.BookId);
        }
Example #6
0
        public async Task <ActionResult> Create(Book book, FormCollection formcollection /*, Author author, Category category*/)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "AccountAdmin"));
            }
            string imageURL, a, c = null;

            try
            {
                imageURL = formcollection["txtImageURL"].ToString();
            }
            catch
            {
                imageURL = "/Content/images/Image.jpg";
            }
            //a = Int32.Parse(formcollection["AuthorID"].ToString());
            //c = Int32.Parse(formcollection["CategoryID"].ToString());
            //var auth = new AuthorDAO();
            //var cete = new CategoryDAO();
            //book.Authors = new List<Author>();
            //book.Authors.Add(auth.ForAuthBook(a));
            //book.Categories = new List<Category>();
            //book.Categories.Add(cete.ForCateBook(c));
            //book.Authors = new List<Author>();
            //book.Authors.Add(author);
            //book.Categories = new List<Category>();
            //book.Categories.Add(category);
            a = formcollection["AuthorID"].ToString();
            c = formcollection["CategoryID"].ToString();
            if (ModelState.IsValid)
            {
                var dao = new BookDAO();
                var rs  = dao.Insert(book, imageURL, a, c); // bay gio nếu insert book thì author đi cùng tự động insert luôn. Làm tương tự cho trường hợp thêm Author
                await db.SaveChangesAsync();

                SetAlert("Thêm Sách Thành Công", "success");
                return(RedirectToAction("Index"));
            }
            ViewBag.ImageBoolID = new SelectList(db.ImageBools, "ImageBoolID", "ImageBoolID", book.ImageBoolID);
            ViewBag.AuthorID    = new SelectList(db.Authors, "AuthorID", "Name", book.Authors.First().AuthorID);
            ViewBag.CategoryID  = new SelectList(db.Categories, "CategoryID", "Name");
            ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", book.PublisherID);
            return(View(book));
        }
        public async Task <ActionResult> Create(Book book, FormCollection formcollection, Author author, Category category)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "AccountAdmin"));
            }
            string imageURL = null;

            try
            {
                imageURL = formcollection["txtImageURL"].ToString();
            }
            catch
            {
                imageURL = "/Content/images/Image.jpg";
            }

            if (ModelState.IsValid)
            {
                var dao = new BookDAO();
                book.isDeleted = false;
                var rs = dao.Insert(book, imageURL);  // bay gio nếu insert book thì author đi cùng tự động insert luôn. Làm tương tự cho trường hợp thêm Author
                if (rs != -1)
                {
                    new AuthorDAO().InsertAuthorsBooks(rs, author.AuthorID);
                    new CategoryDAO().InsertCategorysBooks(rs, category.CategoryID);
                }
                await db.SaveChangesAsync();

                SetAlert("Thêm Sách Thành Công", "success");
                return(RedirectToAction("Index"));
            }
            ViewBag.ImageBoolID = new SelectList(db.Images, "ImageBoolID", "ImageBoolID", book.ImageBoolID);
            ViewBag.AuthorID    = new SelectList(db.Authors, "AuthorID", "Name", book.Authors.First().AuthorID);
            ViewBag.CategoryID  = new SelectList(db.Categories, "CategoryID", "Name");
            ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", book.PublisherID);
            return(View(book));
        }