Exemple #1
0
    protected void OnSubmitOrderButtonClick(object sender, EventArgs e)
    {
        ClearUserMessage();
        string clientEmail = emailTextBox.Text;

        if (clientEmail.Length == 0)
        {
            ShowUserErrorMessage("Your must introduce your email first!");
            return;
        }

        Dictionary <int, int> booksAndAvailabilities = GetSelectBooksAndQuantities();

        if (booksAndAvailabilities.Count == 0)
        {
            ShowUserErrorMessage("Your must select some books first!");
            return;
        }

        BasicOrderData newBasicOrderData = new BasicOrderData();

        newBasicOrderData.BooksIds      = new List <int>(booksAndAvailabilities.Keys);
        newBasicOrderData.BooksQuantity = new List <int>(booksAndAvailabilities.Values);
        try
        {
            storeRestServiceProxy.RegisterOrdersListByClientEmail(clientEmail, newBasicOrderData);
            ShowUserSuccessMessage("Order sucessfully submited!");
        }
        catch (Exception)
        {
            ShowUserErrorMessage("Email not associated to any account!");
        }
    }
        private async Task <BasicOrderData> GetBasicOrderData(Order order)
        {
            if (order == null)
            {
                return(null);
            }
            if (order.Client == null)
            {
                return(null);
            }
            BasicOrderData data   = new BasicOrderData();
            User           client = await userManager.FindByIdAsync(order.Client.Id);

            User employee = null;

            data.Client = order.Client;

            if (order.Employee != null)
            {
                employee = await userManager.FindByIdAsync(order.Employee.Id);

                data.Employee = employee;
            }

            data.TotalPrice = order.Lines.Sum(p => p.Product.Price * p.Quantity);
            data.Order      = order;

            return(data);
        }
        public void RegisterOrdersListByClientEmail(string clientEmail, BasicOrderData basicOrderData)
        {
            Client client = _clients.Find(c => c.Email == clientEmail);

            if (client == default(Client))
            {
                throw new KeyNotFoundException();
            }

            RegisterOrdersListByClientId(client.Id.ToString(), basicOrderData);
        }
        public async Task <IActionResult> Index()
        {
            List <Order> orders = repository.Orders.Include(u => u.Client).Include(e => e.Employee)
                                  .OrderBy(o => o.OrderDateTime).ToList();
            List <BasicOrderData> basicOrderDatas = new List <BasicOrderData>();


            foreach (Order order in orders)
            {
                if (string.IsNullOrEmpty(order.Client.Id))
                {
                    break;
                }
                BasicOrderData orderDetails = await GetBasicOrderData(order);

                basicOrderDatas.Add(orderDetails);
            }

            return(View(basicOrderDatas));
        }
Exemple #5
0
        private void SubmitOrder(object sender, EventArgs e)
        {
            if (selectedBooksListView.Items.Count == 0 || textBoxClientSelectedId.Text.Length == 0)
            {
                return;
            }

            Dictionary <int, int> bookIdToQuantity = new Dictionary <int, int>();

            foreach (ListViewItem listViewItem in selectedBooksListView.Items)
            {
                int bookId   = Convert.ToInt32(listViewItem.SubItems[0].Text);
                int quantity = Convert.ToInt32(listViewItem.SubItems[3].Text);
                CreateOrIncrementEntryInDictionary(bookIdToQuantity, bookId, quantity);
            }

            int clientId = Convert.ToInt32(textBoxClientSelectedId.Text);

            try
            {
                BasicOrderData basicOrderData = new BasicOrderData();
                basicOrderData.BooksIds      = new List <int>(bookIdToQuantity.Keys);
                basicOrderData.BooksQuantity = new List <int>(bookIdToQuantity.Values);
                _store.RegisterOrdersListByClientId(clientId.ToString(), basicOrderData);
            }
            catch
            {
                MessageBox.Show("Internal error has occurred", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //clear resources used on new order creation
            selectedBooksListView.Items.Clear();
            textBoxTotalPrice.Text       = "";
            textBoxClientSelectedId.Text = "";
        }
        public void RegisterOrdersListByClientId(string clientId, BasicOrderData basicOrderData)
        {
            Console.WriteLine("Store RegisterOrdersListByClientId");
            int clientIdNumber = Convert.ToInt32(clientId);
            Dictionary <Book, int> orderAvailableBooks = new Dictionary <Book, int>();
            Dictionary <Book, int> orderPendentBooks   = new Dictionary <Book, int>();

            for (int i = 0; i < basicOrderData.BooksIds.Count; i++)
            {
                int bookId         = basicOrderData.BooksIds[i];
                int wantedQuantity = basicOrderData.BooksQuantity[i];

                int availableQuantity = _booksAvailability[bookId];
                if (availableQuantity >= wantedQuantity)
                {
                    CreateOrIncrementEntryInDictionary(orderAvailableBooks, _booksCollectionMap[bookId], wantedQuantity);
                    if (availableQuantity == wantedQuantity)
                    {
                        GenerateStockFault(_booksCollectionMap[bookId], replenishmentDefaultValue);
                    }
                }
                else
                {
                    int satisfiedQuantity = availableQuantity;
                    if (availableQuantity > 0)
                    {
                        CreateOrIncrementEntryInDictionary(orderAvailableBooks, _booksCollectionMap[bookId], satisfiedQuantity);
                    }
                    CreateOrIncrementEntryInDictionary(orderPendentBooks, _booksCollectionMap[bookId], wantedQuantity - satisfiedQuantity);
                }

                //removes all quantity wanted from availability to leave counters with current availability value
                //a negative value indicates the quantity of that book that is already being waited for other people
                _booksAvailability[bookId] -= wantedQuantity;
            }

            string orderString = "";

            if (orderAvailableBooks.Count != 0)
            {
                ComplexOrder solvedOrder = new ComplexOrder(orderAvailableBooks,
                                                            _clientsMap[clientIdNumber], Order.DispatchedAtDate(), true);
                _ordersSolved.Add(solvedOrder);

                orderString += GenerateInvoiceString(solvedOrder);

                string solvedOrderReport = solvedOrder.State;
                solvedOrderReport += "\n\n";
                solvedOrderReport  = GenerateTableForOrderReport(solvedOrder, solvedOrderReport);
                string clientEmail = solvedOrder.Client.Email;
                string clientName  = solvedOrder.Client.Name;
                EmailSender.SendEmail(solvedOrderReport, "New Order", clientEmail, clientName);
            }

            if (orderPendentBooks.Count != 0)
            {
                ComplexOrder pendentOrder = new ComplexOrder(orderPendentBooks,
                                                             _clientsMap[clientIdNumber], Order.WaitingExpedition, false);
                _pendentOrders.Add(pendentOrder);

                orderString += GeneratePendentOrderReport(pendentOrder);

                foreach (KeyValuePair <Book, int> bookToQuantity in pendentOrder.BooksToQuantity)
                {
                    GenerateStockFault(bookToQuantity.Key, bookToQuantity.Value + replenishmentDefaultValue);
                }

                string pendentOrderReport = pendentOrder.State;
                pendentOrderReport += "\n\n";
                pendentOrderReport  = GenerateTableForOrderReport(pendentOrder, pendentOrderReport);
                string clientEmail = pendentOrder.Client.Email;
                string clientName  = pendentOrder.Client.Name;
                EmailSender.SendEmail(pendentOrderReport, "Pending Order", clientEmail, clientName);
            }


            printerRestServiceProxy.PrintReceipt(orderString);
        }
 public void RegisterOrdersListByClientEmail(string clientEmail, BasicOrderData basicOrderData)
 {
     Channel.RegisterOrdersListByClientEmail(clientEmail, basicOrderData);
 }
 public void RegisterOrdersListByClientId(string clientId, BasicOrderData basicOrderData)
 {
     Channel.RegisterOrdersListByClientId(clientId, basicOrderData);
 }