Exemplo n.º 1
0
        public Order SaveOrder(int branchId, int customerId, int employeeId, List<OrderedBookDescription> orderedBooks)
        {
            var order = new Order
            {
                Customer = RepositoryProvider.GetRepository<Customer>().Find(customerId),
                EmployeeId = employeeId,
                Date = DateTime.Now,
                OrderedBooks = new List<OrderedBook>(orderedBooks.Count)
            };

            var bookAmountRepository = RepositoryProvider.GetRepository<BookAmount>();
            foreach (var orderedBook in orderedBooks)
            {
                var bookAmount = bookAmountRepository.GetAll(ba => ba.Book)
                    .Where(ba => ba.BookId == orderedBook.BookId)
                    .First(ba => ba.BranchId == branchId);
                bookAmount.Amount -= orderedBook.Amount;
                order.OrderedBooks.Add(new OrderedBook
                {
                    BookId = bookAmount.Book.Id,
                    Price = bookAmount.Book.Price,
                    Amount = orderedBook.Amount
                });
            }

            RepositoryProvider.GetRepository<Order>().Add(order);
            RepositoryProvider.SaveChanges();

            return order;
        }
Exemplo n.º 2
0
        public void SaveOrder(Order order, int branchId)
        {
            var bookAmountRepository = RepositoryProvider.GetRepository<BookAmount>();
            foreach (var orderedBook in order.OrderedBooks)
            {
                var bookAmount = bookAmountRepository.GetAll()
                    .Where(ba => ba.BookId == orderedBook.BookId)
                    .First(ba => ba.BranchId == branchId);
                bookAmount.Amount -= orderedBook.Amount;
            }

            RepositoryProvider.GetRepository<Order>().Add(order);
            RepositoryProvider.SaveChanges();
        }
Exemplo n.º 3
0
        public string ValidateOrder(Order order, int branchId)
        {
            var bookAmountRepository = RepositoryProvider.GetRepository<BookAmount>();
            foreach (var orderedBook in order.OrderedBooks)
            {
                var bookAmount = bookAmountRepository.GetAll()
                    .Where(ba => ba.BookId == orderedBook.BookId)
                    .First(ba => ba.BranchId == branchId);

                if (orderedBook.Amount > bookAmount.Amount)
                {
                    return "Max amount for '{0}' is {1}".FormatWith(orderedBook.Book.Title, bookAmount.Amount);
                }
            }

            return null;
        }
        public void Initialize(Employee employee)
        {
            using (StartOperation())
            {
                _employee = employee;
                Order = new Order
                    {
                        EmployeeId = _employee.Id,
                        OrderedBooks = new ObservableCollection<OrderedBook>()
                    };

                ReloadCustomers();
                ReloadBooks();
            }
        }
Exemplo n.º 5
0
 public string ValidateOrder(Order order, int branchId)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public void SaveOrder(Order order, int branchId)
 {
     throw new NotImplementedException();
 }