Exemple #1
0
        public IEnumerable <OrderedBooks> Get(int personId)
        {
            string selectString = "select o.OrdersId, o.TotalPrice, o.PersonId, b.BookId, b.Title, b.Author, b.Price, b.CoverPhoto " +
                                  "from dbo.ORDERS as o " +
                                  "inner join dbo.ORDERBOOK as ob " +
                                  "on o.OrdersId = ob.OrdersId " +
                                  "inner join dbo.BOOK as b " +
                                  "on ob.BookId = b.BookId " +
                                  "where o.Paid = 'false'and o.PersonId = '" + personId +
                                  "'; ";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand(selectString, conn))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        List <OrderedBooks> result = new List <OrderedBooks>();
                        while (reader.Read())
                        {
                            OrderedBooks item = ReadOrderedBook(reader);
                            result.Add(item);
                        }
                        return(result);
                    }
                }
            }
        }
Exemple #2
0
        private OrderedBooks ReadOrderedBook(SqlDataReader reader)
        {
            int     orderId    = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
            decimal totalPrice = reader.IsDBNull(1)? 0 : reader.GetDecimal(1);
            int     personId   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
            int     bookId     = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
            string  title      = reader.IsDBNull(4) ? "" : reader.GetString(4);
            string  author     = reader.IsDBNull(5) ? "" : reader.GetString(5);
            decimal price      = reader.IsDBNull(6) ? 0 : reader.GetDecimal(6);
            string  coverPhoto = reader.IsDBNull(7) ? "" : reader.GetString(7);

            OrderedBooks item = new OrderedBooks()
            {
                orderId        = orderId,
                totalPrice     = totalPrice,
                personId       = personId,
                bookId         = bookId,
                bookTitle      = title,
                bookAuthor     = author,
                bookPrice      = price,
                bookCoverPhoto = coverPhoto
            };

            return(item);
        }
Exemple #3
0
        private async void SaveOrderAsync()
        {
            if (SelectedClient == null)
            {
                ErrorMessage = "Не выбран клиент!";
                return;
            }
            if (OrderedBooks.IsNullOrEmpty())
            {
                ErrorMessage = "Необходимо добавить хотя бы одну книгу.";
                return;
            }
            using (StartOperation())
            {
                var saveOrderModel = new SaveOrderModel
                {
                    OrderedBooks = OrderedBooks,
                    BranchId     = _currentEmployee.BranchId,
                    ClientId     = SelectedClient.Id,
                    EmployeeId   = _currentEmployee.Id,
                    OrderDate    = DateTime.Now
                };

                await SaveOrderOperation.ExecuteAsync(saveOrderModel);
                await Close(true);
            }
        }
Exemple #4
0
        private async void SaveOrderAsync()
        {
            if (SelectedClient == null)
            {
                ErrorMessage = "Выберите клиента";
                return;
            }

            if (OrderedBooks.IsNullOrEmpty())
            {
                ErrorMessage = "Выберите книги";
                return;
            }

            using (StartOperation())
            {
                var saveOrderModel = new SaveOrderModel
                {
                    BranchId     = _currentEmployee.BranchId,
                    ClientId     = SelectedClient.Id,
                    EmployeeId   = _currentEmployee.Id,
                    OrderDate    = DateTime.Now,
                    OrderedBooks = OrderedBooks
                };

                await SaveOrderOperation.ExecuteAsync(saveOrderModel);
                await Close(true);
            }
        }
Exemple #5
0
        public void SelectBook(SearchBookModel bookModel)
        {
            var saveOrderedBookModel = OrderedBooks.FirstOrDefault(ob => ob.BookId == bookModel.Id);

            if (saveOrderedBookModel == null)
            {
                saveOrderedBookModel = new SaveOrderedBookModel
                {
                    BookId    = bookModel.Id,
                    BookTitle = bookModel.BookTitle,
                    Amount    = 0,
                    Price     = bookModel.Price,
                    MaxAmount = bookModel.Amount
                };
                OrderedBooks.Add(saveOrderedBookModel);
            }
            saveOrderedBookModel.Amount += 1;
        }
Exemple #6
0
        private void SelectBook(SearchBookModel book)
        {
            //var bookModel = new SaveOrderedBookModel
            //{
            //    Amount = book.Amount,
            //    Price = book.Price,
            //    BookId = book.BookId,
            //    BookTitle = book.BookTitle
            //};

            SaveOrderedBookModel bookModel = OrderedBooks.FirstOrDefault(ob => ob.BookId == book.BookId);

            if (bookModel == null)
            {
                bookModel           = new SaveOrderedBookModel().CopyProperties(book);
                bookModel.Amount    = 0;
                bookModel.MaxAmount = book.Amount;
                OrderedBooks.Add(bookModel);
            }

            bookModel.Amount += 1;
        }