void AddBook()
        {
            AddEditBookViewModel newBook = new AddEditBookViewModel("Add", BookType.None);
            AddEditBook          newWin  = new AddEditBook();

            newWin.DataContext = newBook;
            newWin.ShowDialog();

            if (newWin.DialogResult == true)
            {
                BookProduct bookToAdd = new BookProduct();
                bookToAdd.BookID      = AllBooks.Count + 1;
                bookToAdd.BookType    = newBook.AddEditItem.BookType;
                bookToAdd.BookName    = newBook.AddEditItem.BookName;
                bookToAdd.BookWriter  = newBook.AddEditItem.BookWriter;
                bookToAdd.PublishYear = newBook.AddEditItem.PublishYear;
                switch (newBook.AddEditItem.BookType)
                {
                case BookType.EBook:
                    (bookToAdd as EbookItem).NumOfDownloads = (newBook.AddEditItem as EbookItem).NumOfDownloads;
                    foreach (var item in (newBook.AddEditItem as EbookItem).LanguagesTranslations)
                    {
                        (bookToAdd as EbookItem).LanguagesTranslations.Add(item);
                    }
                    break;

                case BookType.Printed:
                    (bookToAdd as PrintedItem).NumOfCopied = (newBook.AddEditItem as PrintedItem).NumOfCopied;
                    (bookToAdd as PrintedItem).BookWeight  = (newBook.AddEditItem as PrintedItem).BookWeight;
                    (bookToAdd as PrintedItem).IsAvilable  = (newBook.AddEditItem as PrintedItem).IsAvilable;
                    break;
                }
                AllBooks.Add(bookToAdd);
            }
        }
示例#2
0
        //SerialSample3\form1.cs
        private void button1_Click(object sender, System.EventArgs e)
        {
            //create new book and bookproducts objects
            Product     newProd = new Product();
            BookProduct newBook = new BookProduct();

            //set som eproperties
            newProd.ProductID   = 100;
            newProd.ProductName = "Product Thing";
            newProd.SupplierID  = 10;

            newBook.ProductID   = 101;
            newBook.ProductName = "How to Use Your New Product Thing";
            newBook.SupplierID  = 10;
            newBook.ISBN        = "123456789";
            //add the items to an array
            Product[] addProd = { newProd, newBook };
            //new inventory object using the addProd array
            Inventory inv = new Inventory();

            inv.InventoryItems = addProd;
            //serialize the Inventory object
            TextWriter    tr = new StreamWriter("..\\..\\..\\order.xml");
            XmlSerializer sr = new XmlSerializer(typeof(Inventory));

            sr.Serialize(tr, inv);
            tr.Close();
            MessageBox.Show("Serialized!");
        }
示例#3
0
        // Process all ProductType payments
        public void ProcessPayment(PaymentDTO paymentDto)
        {
            switch (paymentDto.ProductType)
            {
            case ProductType.Book:
                BookProduct book = new BookProduct(paymentDto, _shippingService, _agentService);
                book.ProcessPayments();
                break;

            case ProductType.Membership:
                MembershipProduct membership = new MembershipProduct(paymentDto, _membershipService, _notificationService);
                membership.ProcessPayments();
                break;

            case ProductType.Video:
                VideoProduct video = new VideoProduct(paymentDto);
                video.ProcessPayments();
                break;

            case ProductType.PhysicalProduct:
                PhysicalProduct physicalProduct = new PhysicalProduct(paymentDto, _shippingService, _agentService);
                physicalProduct.ProcessPayments();
                break;
            }
        }
示例#4
0
文件: Form1.cs 项目: alannet/example
        //SerialSample4\form1.cs
        private void button1_Click(object sender, System.EventArgs e)
        {
            //create the XmlAttributes boject
              XmlAttributes attrs=new XmlAttributes();
              //add the types of the objects that will be serialized
              attrs.XmlElements.Add(new XmlElementAttribute("Book",typeof(BookProduct)));
              attrs.XmlElements.Add(new XmlElementAttribute("Product",typeof(Product)));
              XmlAttributeOverrides attrOver=new XmlAttributeOverrides();
              //add to the attributes collection
              attrOver.Add(typeof(Inventory),"InventoryItems",attrs);
              //create the Product and Book objects
              Product newProd=new Product();
              BookProduct newBook=new BookProduct();

              newProd.ProductID=100;
              newProd.ProductName="Product Thing";
              newProd.SupplierID=10;

              newBook.ProductID=101;
              newBook.ProductName="How to Use Your New Product Thing";
              newBook.SupplierID=10;
              newBook.ISBN="123456789";

              Product[] addProd={newProd,newBook};

              Inventory inv=new Inventory();
              inv.InventoryItems=addProd;
              TextWriter tr=new StreamWriter("..\\..\\..\\inventory.xml");
              XmlSerializer sr=new XmlSerializer(typeof(Inventory),attrOver);

              sr.Serialize(tr,inv);
              tr.Close();
            MessageBox.Show("Serialized!");
        }
        public IActionResult updateBook(int id, [FromBody] BookProduct book)
        {
            List <BookProduct> result = _service.updateBook(id, book);

            return(Ok(new response <List <BookProduct> > {
                StatusCode = (int)HttpStatusCode.OK, Message = "successful", Data = result
            }));
        }
        public IActionResult AddBook([FromBody] BookProduct book)
        {
            BookProduct result = _service.AddBook(book);

            return(Ok(new response <BookProduct> {
                StatusCode = (int)HttpStatusCode.OK, Message = "successful", Data = result
            }));
        }
示例#7
0
        public void bookProductNoException()
        {
            //Arrange
            IOrder order = new BookProduct();
            int    result;

            //Assert
            Assert.DoesNotThrow(() => order.ActionTaken(out result));
        }
示例#8
0
        public void BookDetails2()
        {
            // Arrange
            BookProduct bookObj = new BookProduct();
            // Act
            var _bookvar = bookObj.BookDetails("Mybook");

            // Assert
            Assert.AreEqual("book order Successful: Mybook", _bookvar, "Name mismatch");
        }
        public async Task BookProduct(BookProductDto bookProduct)
        {
            Product     product;
            User        user;
            BookProduct book;

            product = await Repository.GetByIdAsync(bookProduct.ProductId);

            user = await UserRepository.GetByEmail(bookProduct.Email);

            if (product == null || user == null)
            {
                throw new KeyNotFoundException();
            }

            book = ProductRepository.GetBookByPersonAndProduct(user.Id, product.Id);

            if (book == null)
            {
                book = new BookProduct
                {
                    ProductId = product.Id,
                    UserID    = user.Id,
                    Quantity  = 1
                };
                await ProductRepository.CreateAsync(book);
            }

            if (bookProduct.Value < 0)
            {
                book.Quantity             -= 1;
                product.AvailableQuantity += 1;
            }
            else
            {
                book.Quantity             += 1;
                product.AvailableQuantity -= 1;
            }

            if (product.AvailableQuantity == 0)
            {
                throw new InvalidOperationException("There is no more quantity available");
            }

            if (product.AvailableQuantity > product.Quantity)
            {
                throw new InvalidOperationException("There is no more quantity available");
            }

            await ProductRepository.UpdateAsync(book);

            await Repository.UpdateAsync(product);
        }
示例#10
0
        public void bookProductFailureTest()
        {
            //Arrange
            IOrder order = new BookProduct();
            int    result;

            //Act
            order.ActionTaken(out result);

            //Assert
            Assert.AreEqual(1, result);
        }
示例#11
0
        public void Test1()
        {
            List <IPurchaseRule> payments = new List <IPurchaseRule>();

            payments.Add(new DuplicatePackingSlipRule());
            payments.Add(new CommissionPaymentRule());
            OrderProcessor processor = new OrderProcessor(payments);
            Product        product   = new BookProduct();

            processor.ProcessOrder(product);
            Assert.Pass();
        }
示例#12
0
        public BookProduct AddBook(BookProduct book)
        {
            ///    SqlCommand command = new SqlCommand("insert into Book(bookName,bookImage,author,description,quantity,price,addedTocard) values(@bookName,@bookImage,@author,@description,@quantity,@price,@addedTocard)");
            SqlCommand command = new SqlCommand("spAddBook")
            {
                CommandType = System.Data.CommandType.StoredProcedure
            };

            command.Parameters.AddWithValue("@bookName", book.bookName);
            command.Parameters.AddWithValue("@bookImage", book.bookImage);
            command.Parameters.AddWithValue("@author", book.author);
            command.Parameters.AddWithValue("@description", book.description);
            command.Parameters.AddWithValue("@quantity", book.quantity);
            command.Parameters.AddWithValue("@price", book.price);
            command.Parameters.AddWithValue("@addedTocard", book.addedTocard);
            _conn.Open();
            command.Connection = _conn;
            command.ExecuteNonQuery();
            _conn.Close();
            return(book);
        }
示例#13
0
        public List <BookProduct> updateBook(int id, BookProduct book)
        {
            List <BookProduct> books = new List <BookProduct>();

            _conn.Open();
            SqlCommand command = new SqlCommand("spUpdateBook", _conn)
            {
                CommandType = System.Data.CommandType.StoredProcedure
            };

            command.Parameters.AddWithValue("@bookId", id);
            command.Parameters.AddWithValue("@bookName", book.bookName);
            command.Parameters.AddWithValue("@bookImage", book.bookImage);
            command.Parameters.AddWithValue("@author", book.author);
            command.Parameters.AddWithValue("@description", book.description);
            command.Parameters.AddWithValue("@quantity", book.quantity);
            command.Parameters.AddWithValue("@price", book.price);
            command.Parameters.AddWithValue("@addedTocard", book.addedTocard);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    books.Add(new BookProduct
                    {
                        /*   bookId = (int)reader[" bookId"],*/
                        bookName    = (string)reader["bookName"],
                        bookImage   = (string)reader["bookImage"],
                        price       = (int)reader["price"],
                        quantity    = (int)reader["quantity"],
                        author      = (string)reader["author"],
                        description = (string)reader["description"]
                    });
                }
            }
            _conn.Close();
            return(books);
        }
示例#14
0
        //SerialSample4\form1.cs
        private void button1_Click(object sender, System.EventArgs e)
        {
            //create the XmlAttributes boject
            XmlAttributes attrs = new XmlAttributes();

            //add the types of the objects that will be serialized
            attrs.XmlElements.Add(new XmlElementAttribute("Book", typeof(BookProduct)));
            attrs.XmlElements.Add(new XmlElementAttribute("Product", typeof(Product)));
            XmlAttributeOverrides attrOver = new XmlAttributeOverrides();

            //add to the attributes collection
            attrOver.Add(typeof(Inventory), "InventoryItems", attrs);
            //create the Product and Book objects
            Product     newProd = new Product();
            BookProduct newBook = new BookProduct();

            newProd.ProductID   = 100;
            newProd.ProductName = "Product Thing";
            newProd.SupplierID  = 10;

            newBook.ProductID   = 101;
            newBook.ProductName = "How to Use Your New Product Thing";
            newBook.SupplierID  = 10;
            newBook.ISBN        = "123456789";

            Product[] addProd = { newProd, newBook };

            Inventory inv = new Inventory();

            inv.InventoryItems = addProd;
            TextWriter    tr = new StreamWriter("..\\..\\..\\inventory.xml");
            XmlSerializer sr = new XmlSerializer(typeof(Inventory), attrOver);

            sr.Serialize(tr, inv);
            tr.Close();
            MessageBox.Show("Serialized!");
        }
示例#15
0
        public List <BookProduct> updateBook(int id, BookProduct book)
        {
            List <BookProduct> result = _repository.updateBook(id, book);

            return(result);
        }
示例#16
0
        public BookProduct AddBook(BookProduct book)
        {
            BookProduct result = _repository.AddBook(book);

            return(result);
        }