public HttpResponseMessage getOrders(bool chefOrCashier, int customerId, string fromDate, string toDate, string email, bool needUnpaidOnly)
        {
            GetOrdersRequestModel requestModel = new GetOrdersRequestModel();

            requestModel.chefOrCashier  = chefOrCashier;
            requestModel.customerId     = customerId;
            requestModel.fromDate       = fromDate;
            requestModel.toDate         = toDate;
            requestModel.email          = email;
            requestModel.needUnpaidOnly = needUnpaidOnly;
            if (requestModel.email.Equals("0"))
            {
                requestModel.email = null;
            }
            if (requestModel.fromDate.Equals("0"))
            {
                requestModel.fromDate = null;
            }
            if (requestModel.toDate.Equals("0"))
            {
                requestModel.toDate = null;
            }
            if (requestModel.customerId == 0)
            {
                requestModel.customerId = 0;
            }
            ErrorModel       errorModel       = null;
            OrderProvider    orderProvider    = new OrderProvider();
            var              orders           = orderProvider.getOrders(requestModel, out errorModel);
            APIResponseModel aPIResponseModel = new APIResponseModel();

            aPIResponseModel.Response = orders;
            aPIResponseModel.Error    = errorModel;
            return(Request.CreateResponse(HttpStatusCode.OK, aPIResponseModel));
        }
 public List <GetOrdersResponseModel> getOrders(GetOrdersRequestModel getOrdersRequestModel, out ErrorModel errorModel)
 {
     errorModel = null;
     try
     {
         Order orderHelper = new Order();
         return(orderHelper.getOrders(getOrdersRequestModel, out errorModel));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #3
0
        public List <GetOrdersResponseModel> getOrders(GetOrdersRequestModel getOrdersRequestModel, out ErrorModel errorModel)
        {
            errorModel = null;
            List <GetOrdersResponseModel> orders = null;
            SqlConnection connection             = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_getOrders, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("chefOrCashier", getOrdersRequestModel.chefOrCashier);
                    command.Parameters.AddWithValue("customer_id", getOrdersRequestModel.customerId);
                    command.Parameters.AddWithValue("fromDate", getOrdersRequestModel.fromDate);
                    command.Parameters.AddWithValue("toDate", getOrdersRequestModel.toDate);
                    command.Parameters.AddWithValue("email", getOrdersRequestModel.email);
                    command.Parameters.AddWithValue("needUnpaidOnly", getOrdersRequestModel.needUnpaidOnly);
                    connection.Open();
                    orders = new List <GetOrdersResponseModel>();
                    SqlDataReader          reader = command.ExecuteReader();
                    GetOrdersResponseModel getOrdersResponseModel = null;
                    int orderIdCheck = 0;
                    while (reader.Read())
                    {
                        MenuItems menuItems = new MenuItems();
                        if (orderIdCheck != Convert.ToInt32(reader["orderId"].ToString()))
                        {
                            if (orderIdCheck != 0)
                            {
                                orders.Add(getOrdersResponseModel);
                            }
                            getOrdersResponseModel                  = new GetOrdersResponseModel();
                            getOrdersResponseModel.menuItems        = new List <MenuItems>();
                            getOrdersResponseModel.orderId          = Convert.ToInt32(reader["orderId"].ToString());
                            getOrdersResponseModel.orderDate        = reader["orderDate"].ToString();
                            getOrdersResponseModel.isDiningIn       = Convert.ToBoolean(reader["isDiningIn"].ToString());
                            getOrdersResponseModel.orderStatusTitle = reader["orderStatusTitle"].ToString();
                            getOrdersResponseModel.billingAmount    = Convert.ToDouble(reader["billingAmount"].ToString());
                            getOrdersResponseModel.isCardPayment    = Convert.ToBoolean(reader["isCardPayment"].ToString());
                            getOrdersResponseModel.firstName        = reader["FirstName"].ToString();
                            getOrdersResponseModel.lastName         = reader["lastName"].ToString();
                            getOrdersResponseModel.statusId         = Convert.ToInt32(reader["orderStatusId"].ToString());
                            getOrdersResponseModel.isPaid           = Convert.ToBoolean(reader["isPaid"].ToString());
                            getOrdersResponseModel.billId           = Convert.ToInt32(reader["billId"].ToString());
                            getOrdersResponseModel.GST              = Convert.ToDecimal(reader["gst"].ToString());
                            getOrdersResponseModel.PST              = Convert.ToDecimal(reader["pst"].ToString());
                            getOrdersResponseModel.totalAfterTax    = Convert.ToDecimal(reader["totalAfterTax"].ToString());
                            getOrdersResponseModel.tip              = Convert.ToDecimal(reader["tip"].ToString());
                            getOrdersResponseModel.isReadyToPay     = Convert.ToBoolean(reader["isReadyToPay"].ToString());
                            int temp = 0;
                            int.TryParse(reader["tableId"].ToString(), out temp);
                            if (temp != 0)
                            {
                                getOrdersResponseModel.tableId = Convert.ToInt32(reader["tableId"].ToString());
                            }
                            orderIdCheck = getOrdersResponseModel.orderId;
                        }
                        menuItems.itemName        = reader["itemName"].ToString();
                        menuItems.itemQty         = Convert.ToInt32(reader["itemQty"].ToString());
                        menuItems.itemDescription = reader["itemDescription"].ToString();
                        menuItems.itemPrice       = Convert.ToDouble(reader["price"].ToString());
                        menuItems.category        = reader["categoryTitle"].ToString();
                        getOrdersResponseModel.menuItems.Add(menuItems);
                    }
                    if (getOrdersResponseModel != null)
                    {
                        orders.Add(getOrdersResponseModel);
                    }
                    command.Dispose();
                }
                return(orders);
            }
            catch (Exception e)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = e.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }