예제 #1
0
        public List <GetTableResponseModel> getTables(int tableId, int capacity, out ErrorModel errorModel)
        {
            errorModel = null;
            List <GetTableResponseModel> tableItems = null;
            SqlConnection connection = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_getTables, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Query Parameters
                    command.Parameters.Add(new SqlParameter("@tableId", System.Data.SqlDbType.Int));
                    command.Parameters["@tableId"].Value = tableId;
                    command.Parameters.AddWithValue("capacity", capacity);

                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    tableItems = new List <GetTableResponseModel>();
                    while (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            GetTableResponseModel getTableResponseModel = new GetTableResponseModel();
                            getTableResponseModel.tableId      = Convert.ToInt32(reader["tableId"].ToString());
                            getTableResponseModel.capacity     = Convert.ToInt32(reader["capacity"].ToString());
                            getTableResponseModel.availability = reader.GetBoolean(reader.GetOrdinal("availability"));

                            tableItems.Add(getTableResponseModel);
                        }
                    }
                    command.Dispose();
                    connection.Close();
                }

                return(tableItems);
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #2
0
        public GetTableResponseModel deleteorModifyTable(TableDeleteRequestModel tableDeleteRequest, out ErrorModel errorModel)
        {
            errorModel = null;
            GetTableResponseModel getTableResponse = null;
            SqlConnection         connection       = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_deleteorModifyTable, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Commands Parameters

                    command.Parameters.Add(new SqlParameter("@isDelete", System.Data.SqlDbType.Bit));
                    command.Parameters["@isDelete"].Value = tableDeleteRequest.isDelete;

                    command.Parameters.Add(new SqlParameter("@tableId", System.Data.SqlDbType.Int));
                    command.Parameters["@tableId"].Value = tableDeleteRequest.tableId;

                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    getTableResponse = new GetTableResponseModel();
                    if (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            getTableResponse.tableId      = Convert.ToInt32(reader["TableId"].ToString());
                            getTableResponse.capacity     = Convert.ToInt32(reader["Capacity"].ToString());
                            getTableResponse.availability = Convert.ToBoolean(reader["Table Active"].ToString());
                        }
                    }
                    command.Dispose();
                    return(getTableResponse);
                }
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #3
0
        public GetTableResponseModel addTable(AddTableRequestModel addTableRequestModel, out ErrorModel errorModel)
        {
            errorModel = null;
            GetTableResponseModel getTableResponseModel = null;
            SqlConnection         connection            = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_addTable, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Command Parameters
                    command.Parameters.AddWithValue("capacity", addTableRequestModel.capacity);
                    #endregion

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            getTableResponseModel              = new GetTableResponseModel();
                            getTableResponseModel.tableId      = Convert.ToInt32(reader["tableId"]);
                            getTableResponseModel.capacity     = Convert.ToInt32(reader["capacity"]);
                            getTableResponseModel.availability = Convert.ToBoolean(reader["availability"]);
                        }
                        command.Dispose();
                        return(getTableResponseModel);
                    }
                    return(null);
                }
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }