public async Task <ActionResult> Post([FromBody] Dish_Ingredient dish_ingredient)
        {
            dish_ingredient.Ing_Name = textInfo.ToTitleCase(dish_ingredient.Ing_Name.ToLower());

            try
            {
                // Making sure that the referred dish and ingredient exist
                await _ingredientRepository.GetByName(dish_ingredient.Ing_Name);

                await _dishRepository.GetById(dish_ingredient.Dish_ID);

                // Inserting record in the Dish_Ingredient table
                await _repository.Insert(dish_ingredient);

                return(Ok("Dish_Ingredient record inserted successfully\n"));
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw an exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(BadRequest("Error: Dish_Ingredient record was not inserted\n"));
            }
        }
        public async Task <ActionResult> Post([FromBody] Order_Dish order_dish)
        {
            try
            {
                // Checking if referenced order and dish exist (if not an exception is thrown)
                await _orderRepository.GetById(order_dish.Order_ID);

                await _dishRepository.GetById(order_dish.Dish_ID);

                // Inserting record in the Order_Dish table
                await _repository.Insert(order_dish);

                // if no exceptionn was thrown by insert above, the record was successfully inserted
                // We update the amount in the corresponding transaction
                Order order = await _orderRepository.GetById(order_dish.Order_ID);

                Dish dish = await _dishRepository.GetById(order_dish.Dish_ID);

                await _transationRepository.updateAmount(order.Transaction_ID, await _transationRepository.getAmount(order.Transaction_ID) + dish.Price);

                return(Ok("Order_Dish record inserted successfully\n"));
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw an exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(BadRequest("Error: Order_Dish record was not inserted\n"));
            }
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            var lstSup = _supRepo.GetAll().Select(x => new SelectListItem
            {
                Value = x.id.ToString(),
                Text  = x.SupplierName.ToString(),
            }).ToList();

            ViewBag.lstSup = lstSup;

            Dish     dish = _dishRepo.GetById(id);
            Supplier sup  = new Supplier();

            sup = _supRepo.GetById(dish.SupplierId);
            DishInfo dishInfo = new DishInfo()
            {
                id           = dish.id,
                DishCode     = dish.DishCode,
                DishName     = dish.DishName,
                SupplierId   = dish.SupplierId,
                SupplierCode = sup.SupplierCode,
                SupplierName = sup.SupplierName,
                Cost         = dish.Cost,
                Description  = dish.Description,
                Image        = dish.Image,
                JugmentPoint = dish.JugmentPoint,
                JugmentQty   = dish.JugmentQty,
                RegisterQty  = dish.RegisterQty,
            };

            return(View("Edit", dishInfo));
        }
Пример #4
0
        public async Task <ActionResult <Dish> > Get(int id)
        {
            try
            {
                // Searching for record in the Dish table
                var response = await _repository.GetById(id);

                return(response);
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw an exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(NotFound("Dish record you are searching for does not exist or URL is wrong"));
            }
        }
Пример #5
0
        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            if (fromDatePicker.Value.Date > toDatePicker.Value.Date)
            {
                MessageBox.Show("\"Дата от\" должна быть раньше чем \"Дата до\"", "", MessageBoxButtons.OK);
            }
            else
            {
                var xlApp = new Microsoft.Office.Interop.Excel.Application();

                object misValue = System.Reflection.Missing.Value;

                Workbook  xlWorkBook  = xlApp.Workbooks.Add(misValue);
                Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.Item[1];

                xlWorkSheet.Cells[1, 1] = "ID заказа";
                xlWorkSheet.Cells[1, 2] = "Дата заказа";
                xlWorkSheet.Cells[1, 3] = "Сумма заказа";
                xlWorkSheet.Cells[1, 4] = "Содержимое заказа";

                var orders     = new OrderRepository(_connectionString).GetReport(fromDatePicker.Value, toDatePicker.Value);
                var dishesRepo = new DishRepository(_connectionString);


                for (int i = 0; i < orders.Count; i++)
                {
                    xlWorkSheet.Cells[2 + i, 1] = orders[i].OrderID;
                    xlWorkSheet.Cells[2 + i, 2] = orders[i].OrderDate.ToString("dd-MM-yyyy");
                    xlWorkSheet.Cells[2 + i, 3] = orders[i].Total;

                    var orderDetailsString = string.Empty;

                    foreach (var pair in orders[i].DishesAndCounts)
                    {
                        orderDetailsString += dishesRepo.GetById(pair.Key).DishName + " " + pair.Value + " порции(-й) , ";
                    }
                    xlWorkSheet.Cells[2 + i, 4] = orderDetailsString;
                }

                xlWorkBook.SaveAs($"{AppDomain.CurrentDomain.BaseDirectory}Отчет-с-{fromDatePicker.Value:dd-MM-yyyy}-по-{toDatePicker.Value:dd-MM-yyyy}.xlsx", XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue,
                                  XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

                xlWorkBook.Close();
                xlApp.Quit();

                Marshal.ReleaseComObject(xlWorkSheet);
                Marshal.ReleaseComObject(xlWorkBook);
                Marshal.ReleaseComObject(xlApp);

                MessageBox.Show("Отчет успешно экспортирован", "", MessageBoxButtons.OK);
                Close();
            }
        }
Пример #6
0
        private void showDetails_Click(object sender, EventArgs e)
        {
            var selectedOrderRow = ordersDataGridView.SelectedRows[0];
            var selectedOrder    = (Order)selectedOrderRow.DataBoundItem;

            var orderDetailsString = string.Empty;
            var dishesRepo         = new DishRepository(_connectionString);

            foreach (var pair in selectedOrder.DishesAndCounts)
            {
                orderDetailsString += dishesRepo.GetById(pair.Key).DishName + " " + pair.Value + " порции(-й)\n";
            }

            if (string.IsNullOrEmpty(orderDetailsString))
            {
                orderDetailsString = "Заказ пуст";
            }

            MessageBox.Show($"{orderDetailsString}", "Содержимое заказа", MessageBoxButtons.OK);
        }
Пример #7
0
        private void btnExportToPdf_Click(object sender, EventArgs e)
        {
            if (fromDatePicker.Value.Date > toDatePicker.Value.Date)
            {
                MessageBox.Show("\"Дата от\" должна быть раньше чем \"Дата до\"", "", MessageBoxButtons.OK);
            }
            else
            {
                const int COLUMN_COUNT = 4;

                var orders = new OrderRepository(_connectionString).GetReport(fromDatePicker.Value, toDatePicker.Value);

                PdfPTable pdfTable = new PdfPTable(COLUMN_COUNT);
                pdfTable.DefaultCell.Padding = 5;
                pdfTable.WidthPercentage     = 100;

                var cell = new PdfPCell(new Phrase("OrderID"));
                cell.BackgroundColor     = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#cfc6c6"));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable.AddCell(cell);

                cell = new PdfPCell(new Phrase("Date of order"));
                cell.BackgroundColor     = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#cfc6c6"));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable.AddCell(cell);

                cell = new PdfPCell(new Phrase("Total"));
                cell.BackgroundColor     = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#cfc6c6"));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable.AddCell(cell);

                cell = new PdfPCell(new Phrase("Details"));
                cell.BackgroundColor     = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#cfc6c6"));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable.AddCell(cell);

                var dishesRepo = new DishRepository(_connectionString);
                //creating table data (actual result)
                foreach (var order in orders)
                {
                    pdfTable.AddCell(order.OrderID.ToString());

                    pdfTable.AddCell(order.OrderDate.ToString("dd-MM-yyyy"));

                    pdfTable.AddCell(order.Total.ToString());

                    var orderDetailsString = string.Empty;

                    foreach (var pair in order.DishesAndCounts)
                    {
                        orderDetailsString += dishesRepo.GetById(pair.Key).DishName + " " + pair.Value + " порции(-й) , ";
                    }
                    pdfTable.AddCell(orderDetailsString);
                }


                using (var fileStream = new FileStream($"{ AppDomain.CurrentDomain.BaseDirectory }Отчет -с-{ fromDatePicker.Value:dd-MM-yyyy}-по-{ toDatePicker.Value:dd-MM-yyyy}.pdf", FileMode.OpenOrCreate))
                {
                    Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                    PdfWriter.GetInstance(pdfDoc, fileStream);
                    pdfDoc.Open();
                    pdfDoc.Add(pdfTable);
                    pdfDoc.Close();
                    fileStream.Close();
                }

                MessageBox.Show("Отчет успешно экспортирован", "", MessageBoxButtons.OK);
                Close();
            }
        }
Пример #8
0
        public async Task <ActionResult> Post([FromBody] Order_No_Transaction order_no_transaction, int tableno, int dish_id, int?tran_id = null)
        {
            try
            {
                // Checking if tableno and dish_id, and user_id exist (otherwise an exception is thrown)
                await _tableRepository.GetById(tableno);

                await _dishRepository.GetById(dish_id);

                await _customerRepository.GetById(order_no_transaction.User_ID);

                int last_tran_inserted = -1;
                // Opening a transaction for the order
                if (tran_id == null)
                {
                    // Creating a default transaction
                    Transaction def_tran = new Transaction {
                        Amount = (decimal)0.0, Date_Time = order_no_transaction.Date_Time
                    };
                    // Inserting default transaction into the Transaction table
                    await _transactionRepository.Insert(def_tran);

                    // Inserting transaction into Customer_Transaction table
                    last_tran_inserted = await _transactionRepository.getLastTransactionInserted();

                    await _customer_TransactionRepository.Insert(new Customer_Transaction { User_ID = order_no_transaction.User_ID, Transaction_ID = last_tran_inserted });

                    // Inserting record in the Order table
                    await _repository.Insert(new Order { User_ID = order_no_transaction.User_ID, Transaction_ID = last_tran_inserted, Date_Time = order_no_transaction.Date_Time });
                }
                else // The id of an existing transaction was passed, so we just add orders to that transaction.
                {
                    // Checking if provided transaction exists (otherwise an exception is thrown)
                    await _transactionRepository.GetById((int)tran_id);

                    // Inserting record in the Order table
                    await _repository.Insert(new Order { User_ID = order_no_transaction.User_ID, Transaction_ID = (int)tran_id, Date_Time = order_no_transaction.Date_Time });
                }

                // Getting last inserted order from Order table
                int last_order_id = await _repository.getLastOrderInserted();

                await _in_store_orderRepository.Insert(new In_Store_Order { Order_ID = last_order_id, TableNo = tableno });

                // Inserting new order and dish into Order_Dish table
                await _orderDishRepository.Insert(new Order_Dish { Order_ID = last_order_id, Dish_ID = dish_id });

                // Updating total amount of transaction respectively and returning a success message
                if (tran_id == null) // If tran_id was not provided
                {
                    await _transactionRepository.updateAmount(last_tran_inserted, await _transactionRepository.getAmount(last_tran_inserted) + await _repository.getCost(last_order_id));

                    return(Ok("Records inserted successfully in the Order, In_Store_Order, Transaction, and Order_Dish Tables"));
                }
                else // tran_id was provided (we added the order to an existing transaction
                {
                    await _transactionRepository.updateAmount((int)tran_id, await _transactionRepository.getAmount((int)tran_id) + await _repository.getCost(last_order_id));

                    return(Ok("Records inserted successfully in the Order, In_Store_Order, and Order_Dish tables\n"));
                }
            }
            catch (InvalidCastException)
            {
                // Invalid parameters in URI
                return(BadRequest("Provided table number, transaction id, or dish_id do not exist. Please check inputs!\n"));
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw an exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(BadRequest("Error: Order record was not inserted\n"));
            }
        }